fdisk

  是Linux下常用的磁盘分区工具。受mbr分区表的限制,fdisk工具只能给小于2TB的磁盘划分分区。如果使用fdisk对大于2TB的磁盘进行分区,虽然可以分区,但其仅识别2TB的空间,所以磁盘容量若超过2TB,就要使用parted分区工具(后面会讲)进行分区。
fdisk [选项] [设备名] 
-l    显示所有磁盘分区的信息
[root@cs6 ~]# fdisk -l #<==查看当前系统所有磁盘的分区信息。

Disk /dev/sda: 32.2 GB, 32212254720 bytes  #<==磁盘/dev/sda的大小。
255 heads, 63 sectors/track, 3916 cylinders #<==255个虚拟磁头,63个扇区/磁道,3916 个柱面。
Units = cylinders of 16065 * 512 = 8225280 bytes #<==一个柱面大小8225280 bytes。
Sector size (logical/physical): 512 bytes / 512 bytes #<==每个扇区的字节数。
I/O size (minimum/optimal): 512 bytes / 512 bytes #<==每次读写的字节数。
Disk identifier: 0x0001038a Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 3917 30944256 8e Linux LVM Disk /dev/mapper/vg_cs6-lv_root: 28.5 GB, 28462546944 bytes
255 heads, 63 sectors/track, 3460 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/mapper/vg_cs6-lv_swap: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Device:分区,这里有二个分区;
Boot:启动分区,用*表示的是启动分区;
Start;表示开始的柱面:
End:表示结束的在面;
Blocks:block 块数量;
Id:分区类型Id;
System:分区类型。

在虚拟机(VMware Workstation Pro)模拟磁盘分区实战

步骤1:先在虚拟机关机状态下添加一块1GB硬盘,若是在开机状态下添加,则需要重启系统。
步骤2:重启系统后查看添加的磁盘。 
[root@cs6 ~]# fdisk -l

Disk /dev/sdb: 1073 MB, 1073741824 bytes #<==刚刚新添加的硬盘名为sdb,是第二块盘。
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
还可以直接指定特定分区查看信息。
[root@cs6 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

步骤3:交互式分区实践。

[root@cs6 ~]# ls /dev/sd* #<=需查看分区前设备的状态。
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb [root@cs6 ~]# fdisk /dev/sdb #<==不加参数,直接接设备名就可以分区。
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x34d8eef3.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to #<==提示使用-c关闭dos兼容模式。
sectors (command 'u'). #<==提示-u参数使用扇区为单位分区。 Command (m for help): m #<= m是帮助,需要人工输入m后回车,
Command action
a toggle a bootable flag #<==设置引导扇区。
b edit bsd disklabel #<==编辑bsd卷标。
c toggle the dos compatibility flag #<==设置dos兼容扇区。
d delete a partition #<==删除一个分区。
l list known partition types #<==查看分区类型对应编号列表。
m print this menu #<==打印帮助菜单。
n add a new partition #<==新建一个分区。
o create a new empty DOS partition table #<==创建一个新的空DOS分区表,
p print the partition table #<==打印分区表。
q quit without saving changes #<==退出不保存更改
s create a new empty Sun disklabel #<==创建新的空 sun卷标。
t change a partition's system id #<==更改分区系统id。
u change display/entry units #<==改变显示/条目的单位。
v verify the partition table #<==验证分区表。
w write table to disk and exit #<==将操作写入分区表并退出程序。
x extra functionality (experts only) #<==额外的功能。 Command (m for help): n #<==新建一个分区,需要人工输入n后回车。
Command action
e extended #<==创建扩展分区。
p primary partition (1-4) #<==创建主分区(编号1-4)。
p
Partition number (1-4): 1 #<==设置分区编号为1,需要人工输入1后回车。
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +100M
#<==设置结束柱面(130)或分区大小(+100M),因为要划分出指定大小的分区,所以常用+100M这种方法,如果分区时使用fdisk -cu /dev/sdb,则这里就会使用扇区为单位来进行分区。
Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux Command (m for help): n
Command action
e extended
p primary partition (1-4)
2
Invalid partition number for type `2'
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (15-130, default 15):
Using default value 15
Last cylinder, +cylinders or +size{K,M,G} (15-130, default 130):
Using default value 130 #<==按回车键,默认设置结束柱而号130。 Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 130 931770 5 Extended Command (m for help): n
Command action
l logical (5 or over) #<=分了扩展分区,这里自动变为逻辑分区。
p primary partition (1-4)
p
Partition number (1-4): 3
No free sectors available #<==不能再创建主分区,没有磁盘空间了。
#<==再新建一个分区。
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (15-130, default 15): #<=按回车键,开始柱面号为15。
Using default value 15
Last cylinder, +cylinders or +size{K,M,G} (15-130, default 130): +400M
#<==设置分区大小为400MB
Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 130 931770 5 Extended
/dev/sdb5 15 66 417658+ 83 Linux Command (m for help): n #<==新建一个分区。
Command action
l logical (5 or over)
p primary partition (1-4)
l #<==再新建一个逻辑分区。
First cylinder (67-130, default 67):
Using default value 67
Last cylinder, +cylinders or +size{K,M,G} (67-130, default 130):
Using default value 130 Command (m for help): p #<==打印分区表。 Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 130 931770 5 Extended
/dev/sdb5 15 66 417658+ 83 Linux
/dev/sdb6 67 130 514048+ 83 Linux Command (m for help): w #<==将操作写入分区表生效并退出程序。
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@cs6 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6
[root@cs6 ~]#
[root@cs6 ~]# yum -y install parted
[root@cs6 ~]# partprobe /dev/sdb #<==执行该命令通知内核分区表已更改,此步是不重启让分区表生效的命令。
步骤4:格式化磁盘。
[root@cs6 ~]# mkfs.ext4 /dev/sdb1    #<==只有格式化后的磁盘才能挂载到系统中使用,后面将会详细讲解mkfs.ext4命令。
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
28112 inodes, 112420 blocks
5621 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
14 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729 正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override. [root@cs6 ~]# tune2fs -c -1 /dev/sdb1 #<=执行这个命令可以避免磁盘挂载自动检查磁盘,后面将会讲解tune2fs命令。
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1

步骤5:挂载磁盘分区。

[root@cs6 ~]# vi /etc/fstab    #<==最后一行加入,要开机自动挂载磁盘就要加入/etc/fstab或将上面的mount命令放入/etc/rc.local中。

/dev/sdb1              /mnt                     ext4       defaults     0  0

[root@cs6 ~]# vi /etc/rc.local    #<==或者编辑/etc/rc.local,最后一行加入,两种方法二选一。
mount /dev/sdb1 /mnt

步骤6:其他事项。

    用交互指令d删除分区时要小心,看好分区的序号,如果删除了扩展分区,那么扩展分区之下的逻辑分区都会删除,所以操作时一定要小心。如果不小心操作错了,直接使用交互指令q不保存退出,这样先前的操作就会无效。如果输入w(保存指令)则会保存所有修改。
[root@cs6 ~]# fdisk /dev/sdb

Command (m for help): d
Partition number (1-6): 2 Command (m for help): p Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x34d8eef3 Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux

fdsik 非交互式分区(批量分区案例)

 
 
以下是实现非交互式分区的代码。
fdisk /dev/sdb <<EOF    #<==也可以将下面的内容写入文本文件,然后读文本执行。
n
P
1

+100M
n
e
2

n
l
+400
n
l

p
w
EOF
 
 
 
 
-

8.1 fdisk:磁盘分区工具的更多相关文章

  1. 浅谈Linux下傻瓜式磁盘分区工具cfdisk的使用

    对于新手来说,Linux环境下的磁盘分区可能还会存在一些困难.对于熟悉Linux的朋友来说,我们还有fdisk.parted(2TB以上的磁盘分区使用)等磁盘分区工具可以使用.在我们新增磁盘或者在原来 ...

  2. (转)centos7.4 fdisk磁盘分区 格式化 挂载

    centos7.4 fdisk磁盘分区 格式化 挂载 原文:http://blog.csdn.net/capecape/article/details/78499351 1.查看系统中有多少可以识别的 ...

  3. fdisk 磁盘分区命令

    fdisk fdisk磁盘分区命令 -v    打印 fdisk 的版本信息并退出.-l    列出指定设备的分区表信息并退出. 如果没有给出设备,那么使用那些在 /proc/partitions ( ...

  4. linux 大容量磁盘分区工具parted

    1. Msdos和Gpt的区别 fdisk  :只能分msdos分区parted :可以分msdos和gpt分区 2. MSDOS特点最大支持2TB卷大小.每个磁盘最多只能有4个主分区(或3个主分区, ...

  5. Linux下的两种磁盘分区工具的使用

    如何使用fdisk和parted分区工具来进行硬盘分区,下面我来说一下在Linux系统中这两种硬盘分区工具的使用方法:     ----------fdisk分区工具----------       ...

  6. Linux磁盘分区工具的使用

    ----------fdisk分区工具----------   一..下面来介绍fdisk分区工具的命令格式:    fdisk是传统的Linux硬盘分区工具,也是Linux系统中最常用的一种硬盘分区 ...

  7. [转]使用fdisk磁盘分区和 Linux 文件系统

    概述 在本文中,学习磁盘分区和 Linux 文件系统相关内容.学习: 创建分区 使用 mkfs 命令来设置 ext2.ext3.ext4.xfs.Reiser v3 和 vfat 文件系统 创建和管理 ...

  8. Linux学习(十三)du、df、fdisk磁盘分区

    一.du du命令是查看文件或者目录大小的命令. 一般使用du -sh 查看,不用-sh参数意义也不大,应为不用这个参数,它会把目录下的所有文件大小递归的显示出来,就像这样: 如果用-sh参数: [r ...

  9. fdisk磁盘分区与挂载

    参考博客:https://blog.csdn.net/capecape/article/details/78499351?locationNum=6&fps=1 1.查看磁盘分区情况.root ...

随机推荐

  1. NPM 与 NPX 区别

    NPM 和 NPX 区别 NPM Node Package Manager npm 是 Node.js 的软件包管理器,其目标是自动化的依赖性和软件包管理 NPX npx 是执行 Node 软件包的工 ...

  2. 为什么 DNS 协议使用 UDP?只使用了 UDP 吗?

    尽人事,听天命.博主东南大学硕士在读,携程 Java 后台开发暑期实习生,热爱健身和篮球,乐于分享技术相关的所见所得,关注公众号 @ 飞天小牛肉,第一时间获取文章更新,成长的路上我们一起进步 本文已收 ...

  3. Day13_67_interrupt() 方法

    interrupt() 方法 中断线程 * interrupt()方法的简单理解 - interrupt() 方法只是改变线程的阻塞状态而已,让一个正在阻塞状态的线程,恢复执行.但是它不会中断一个正在 ...

  4. kubectl简介

    kubectl简介 kubectl是操作k8s集群的命令行工具,安装在k8s的master节点,kubectl在$HOME/.kube目录中查找一个名为config的文件, 你可以通过设置Kubeco ...

  5. Innodb中的快照读和当前读

    一.前言 上篇文章记录了对MVCC的相关理解,其中有提到快照读.其实在MVCC并发控制中,读操作可以分为两类:快照读(snapshot read)和当前读(current read)   二.什么是快 ...

  6. 带你温习一下webpack配置

    前言 你知道node.webpack和npm之间的关系吗? 首先来介绍一下node.webpack和npm的有什么样的关系. 我们知道webpack是对我们所开发的html.css.js等模块化开发的 ...

  7. scrapy爬虫框架调用百度地图api数据存入数据库

    scrapy安装配置不在本文 提及, 1.在开始爬取之前,必须创建一个新的Scrapy项目.进入自定义的项目目录中,运行下列命令 scrapy startproject mySpider 其中, my ...

  8. Laravel 定时任务 任务调度 可手动执行

    1.创建一个命令 php artisan make:command TestCommand 执行成功后会提示: Console command created successfully. 生成了一个新 ...

  9. 【并发编程】Java中的锁有哪些?

    0.死锁 两个或者两个以上的线程在执行过程中,由于竞争资源或者由于彼此通信而造成的一种阻塞现象,若无外力作用,他们都将无法让程序进行下去: 死锁条件: 不可剥夺条件: T1持有的资源无法被T2剥夺 请 ...

  10. UC-Android逆向工程师 面试题1的分析

    1.简介 这个题目是一位吾爱破解的坛友在面试UC的Android逆向工程事时,遇到的题目.此题不难,与阿里移动去年移动安全比赛的题目差不多,题目的验证方式也是查表对比,并且这个表的数据是放在文件中的. ...