关于fdisk命令

fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区。

[root@loclhost ~]# fdisk  /dev/sdb
Command (m for help): m         #输入m列出常用的命令
Command action
   a   toggle a bootable flag               #切换分区启动标记
   b   edit bsd disklabel                   #编辑sdb磁盘标签
   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   #创建新的空白分区表
   p   print the partition table            #显示分区表的信息
   q   quit without saving changes          #不保存退出
   s   create a new empty Sun disklabel     #创建新的Sun磁盘标签
   t   change a partitions system id        #修改分区ID,可以通过l查看id
   u   change display/entry units           #修改容量单位,磁柱或扇区
   v   verify the partition table           #检验分区表
   w   write table to disk and exit         #保存退出
   x   extra functionality (experts only)   #拓展功能

 fdisk创建主分区

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)  #主分区
   e   extended  #扩展分区
Select (default p): p   #选择创建主分区
Partition number (1-4, default 1):  #默认创建第一个主分区
First sector (2048-2097151, default 2048): #默认扇区回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +50M #分配50MB

fdisk创建扩展分区

Command (m for help): n  #新建分区
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e   #创建扩展分区
Partition number (2-4, default 2):
First sector (104448-2097151, default 104448):
Using default value 104448
Last sector, +sectors or +size{K,M,G} (104448-2097151, default 2097151): #空间都给到扩展分区

fdisk创建逻辑分区

Command (m for help): n  #新建分区
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l   #创建逻辑分区
Adding logical partition 5
First sector (106496-2097151, default 106496):
Using default value 106496
Last sector, +sectors or +size{K,M,G} (106496-2097151, default 2097151): +100M  #分配100MB空间

fdisk查看分区情况,并保存

Command (m for help): p #查看分区创建
Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      104447       51200   83  Linux
/dev/sdb2          104448     2097151      996352    5  Extended
/dev/sdb5          106496      311295      102400   83  Linux

#保存分区
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
原文地址:https://www.cnblogs.com/HByang/p/11418534.html