linux磁盘分区工具fdisk命令


父目录:linux磁盘管理

利用fdisk对磁盘进行分区
虽然 MBR 分区表在未来应该会慢慢的被淘汰,毕竟现在磁盘容量随便都大于 2T 以上了。而对于 在 CentOS 7.x 中还无法完整支持 GPT 的 fdisk 来说, 这家伙真的英雄无用武之地了啦!不过依旧 有些旧的系统,以及虚拟机的使用上面,还是有小磁盘存在的空间!这时处理 MBR 分区表, 就得要使用 fdisk了!
因为 fdisk 跟 gdisk 使用的方式几乎一样!只是一个使用 ? 作为指令提示数据,一个使用 m 作为提示这样而已。 此外,fdisk 有时会使用磁柱 (cylinder) 作为分区的最小单位,与 gdisk 默认使用sector 不太一样!大致上只是这点差别! 另外, MBR 分区是有限制的 (Primary, Extended, Logical...)! 不要忘记了!这里不使用范例了,毕竟示范机上面也没有 MBR 分区表... 这里仅列出相关的指令给大家对照参考啰!

              [root@initroot ~]# fdisk /dev/sda
              # 输入 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 #不储存离开 fdisk 程序
              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)
              #删除一个 partition
              #新增一个 partition
              #将刚刚的动作写入分区表
              

fdisk命令可以对磁盘进行管理,比如显示磁盘信息,对磁盘分区。

选项:

-b<分区大小>:指定每个分区的大小;
-l:列出指定的外围设备的分区表状况;
-s<分区编号>:将指定的分区大小输出到标准输出上,单位为区块;
-u:搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址;
-v:显示版本信息。

fdisk后面跟磁盘设备文件,或者直接输入fdisk即可进入fdisk的交互界面,在该界面中,用户可以进行创建分区、激活分区、删除分区和查看分区信息等操作:

fdisk /dev/sda
不必记住fdisk的所有命令,只需要根据fdisk的提示,进行相应的操作即可。按照提示输入m即可查看帮助信息:
peter@peter-VirtualBox:~$ sudo fdisk /dev/sda 
[sudo] password for peter: 
Welcome to fdisk (util-linux 2.31.1). 
Changes will remain in memory only, until you decide to write them. 
Be careful before using the write command. 
Command (m for help): m 
Help: 
DOS (MBR) 
a toggle a bootable flag 
b edit nested BSD disklabel 
c toggle the dos compatibility flag 
Generic 
d delete a partition 
F list free unpartitioned space 
l list known partition types 
n add a new partition 
p print the partition table 
t change a partition type 
v verify the partition table 
i print information about a partition 
Misc 
m print this menu 
u change display/entry units 
x extra functionality (experts only) 
Script 
I load disk layout from sfdisk script file 
O dump disk layout to sfdisk script file 
Save & Exit 
w write table to disk and exit 
q quit without saving changes 
Create a new label 
g create a new empty GPT partition table 
G create a new empty SGI (IRIX) partition table 
o create a new empty DOS partition table 
s create a new empty Sun partition table 
根据m打印的帮助信息,可以看到p用于打印磁盘的分区表,查看磁盘分区情况:
Command (m for help): p
Disk /dev/sda: 90 GiB, 96636764160 bytes, 188743680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe89012ea
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 188741631 188739584 90G 83 Linux
输入d删除一个磁盘分区
输入n可根据提示添加新分区

Usage:
fdisk [options] <disk> change partition table
fdisk [options] -l [<disk>] list partition table(s)
Display or manipulate a disk partition table.
Options:
-b, --sector-size <size> physical and logical sector size
-B, --protect-boot don't erase bootbits when creating a new label
-c, --compatibility[=<mode>] mode is 'dos' or 'nondos' (default)
-L, --color[=<when>] colorize output (auto, always or never)
colors are enabled by default
-l, --list display partitions and exit
-o, --output <list> output columns
-t, --type <type> recognize specified partition table type only
-u, --units[=<unit>] display units: 'cylinders' or 'sectors' (default)
-s, --getsz display device size in 512-byte sectors [DEPRECATED]
--bytes print SIZE in bytes rather than in human readable format
-w, --wipe <mode> wipe signatures (auto, always or never)
-W, --wipe-partitions<mode> wipe signatures from new partitions (auto, always or never)
-C, --cylinders <number> specify the number of cylinders
-H, --heads <number> specify the number of heads
-S, --sectors <number> specify the number of sectors per track
-h, --help display this help
-V, --version display version
Available output columns:
gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID
dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S Start-C/H/S
bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize
sgi: Device Start End Sectors Cylinders Size Type Id Attrs
sun: Device Start End Sectors Cylinders Size Type Id Flags
For more details see fdisk(8).

initroot编辑整理,转载请注明www.initroot.com

100次点赞 100次阅读