Linux fdisk 命令 - 管理磁盘分区表
介绍
fdisk 是一个创建和维护分区表的程序,它兼容 DOS 类型的分区表、BSD 或者 SUN 类型的磁盘列表。
fdisk 命令可用于观察硬盘实体使用情况,也可对硬盘分区。它采用传统的问答式界面,而非类似 DOS fdisk 的 cfdisk 互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。
语法:
fdisk [选项] [参数]
选项:
-b <分区大小>:指定每个分区的大小。-l:列出指定的外围设备的分区表状况。-s <分区编号>:将指定的分 区大小输出到标准输出上,单位为区块。-u:搭配 "-l" 参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址。-v:显示版本信息。
参数: 指定要进行分区或者显示分区的硬盘设备文件。
分区菜单操作说明:
m:显示菜单和帮助信息a:活动分区标记/引导分区d:删除分区l:显示分区类型n:新建分区p:显示分区信息q:退出不保存t:设置分区号v:进行分区检查w:保存修改x:扩展应用,高级功能
示例
显示当前分区情况:
$ sudo fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
对磁盘进行分区,首先选择要进行操作的磁盘(如 /dev/sdb):
$ sudo fdisk /dev/sdb
输入 m 列出可以执行的命令:
command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
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
t change a partition's system 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):