fdisk

查看磁盘使用情况和磁盘分区,创建,删除和修改磁盘分区。

语法

fdisk [options] <disk>        => 改变分区表
fdisk [options] -l [<disk>]   => 列出分区表

选项

-b, --sector-size <size>      设置物理和逻辑扇区大小:512、1024、2048、4096。
-B, --protect-boot            创建一个新标签时不删除引导位,引导保护。
-c, --compatibility[=<mode>]  兼容模式:'dos' 或 'nondos'(default)。
-L, --color[=<when>]          带颜色输出,支持以下三个参数:
                                  auto     自动
                                  always   总是
                                  never    从不
                              默认是启用的。
-l, --list                    显示分区并退出。
-o, --output <list>           以列的方式输出。
-t, --type <type>             仅能识别指定的分区表类型。
-u, --units[=<unit>]          显示单位,支持以下两个参数:
                                  cylinders  柱面。
                                  sectors    扇区,这是默认的。
-s, --getsz                   以512字节扇区显示设备大小[已弃用]
    --bytes                   以字节格式打印,而不是以人类能够阅读的单位格式。

-C, --cylinders <number>      指定柱面数量。
-H, --heads <number>          指定磁头数量。
-S, --sectors <number>        指定每个磁道的扇区数量。


-h, --help                    显示这个命令的帮助信息并退出。
-V, --version                 输出版本信息并退出。

示例

对磁盘/dev/sdb/进行分区操作:

[root@localhost ~]# fdisk /dev/sdb
# 输入 m 查看可执行的命令
command (m for help): 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)             额外功能(仅限专家)

# 输入 p 列出磁盘目前的分区情况
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           1        8001   8e  Linux LVM
/dev/sdb2               2          26      200812+  83  Linux

# 输入 d 然后选择分区,删除现有分区
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2

# 查看分区情况,确认分区已经删除
Command (m for help): print
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
Command (m for help):

# 输入n建立新的磁盘分区,首先建立两个主磁盘分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

# 输入p建立主分区
Partition number (1-4): 1  # 分区号
First cylinder (1-391, default 1):  # 分区起始位置
Using default value 1
last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100  # 分区结束位置,单位为扇区

# 输入n再建立一个分区
Command (m for help): n  
Command action
   e   extended
   p   primary partition (1-4)

# 输入p新建一个主分区
Partition number (1-4): 2  # 分区号为2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M  #分区结束位置,单位为M

# 输入p确认分区建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux

# 再建立一个逻辑分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

# 输入e选择创建一个扩展分区
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):
Using default value 391

# 输入p确认扩展分区建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended

# 在扩展分区上建立两个逻辑分区
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)

# 选择l创建逻辑分区
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M    
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391

# 确认逻辑分区建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended
/dev/sdb5             126         175      401593+  83  Linux
/dev/sdb6             176         391     1734988+  83  Linux
Command (m for help):

# 输入w保存操作信息
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
乐在分享!~~
原文地址:https://www.cnblogs.com/network-ren/p/15513853.html