13.5. 使用 fdisk 重新定义分区大小
fdisk
实用程序允许您创建和操作 GPT、R MBR、SGI 和 BSD 分区表。建议在带有 GUID 分区表(GPT)的磁盘上,建议使用 parted
工具,因为 fdisk
GPT 支持处于实验性阶段。
在调整分区大小前,备份 文件系统中存储的数据并测试流程,因为使用
fdisk
更改分区大小的唯一方法是通过删除和重新创建分区。
重要
您大小的分区必须是特定磁盘上的最后一个分区。
红帽只支持扩展和重新定义 LVM 分区大小。
过程 13.4. 调整分区大小
以下过程仅提供 reference. follows
使用
fdisk
调整分区大小:
- 卸载该设备:
#
umount /dev/vda - 运行 fdisk disk_name。例如:
#
fdisk /dev/vda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): - 使用
p
选项确定要删除的分区的行号。Command (m for help): p Disk /dev/vda: 16.1 GB, 16106127360 bytes, 31457280 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 Disk label type: dos Disk identifier: 0x0006d09a Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 31457279 15215616 8e Linux LVM
- 使用 d 选项删除分区。如果有多个分区可用,fdisk 会提示您提供要删除的多个分区:
Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 is deleted
- 使用
n
选项创建分区并按照提示进行操作。允许足够空间以供将来重新定义大小。fdisk 默认行为(按Enter
)是使用设备上的所有空间。您可以根据扇区指定分区的结束,或使用 + <size> <suffix> 指定人类可读的大小,如 +500M 或 +10G。如果您不想使用所有可用空间,红帽建议使用人类可读的大小规格,因为 fdisk 将分区的末尾与物理扇区一致。如果您通过提供准确数字(扇区)来指定大小,fdisk 不会对齐分区的末尾。Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): *Enter* Using default response p Partition number (2-4, default 2): *Enter* First sector (1026048-31457279, default 1026048): *Enter* Using default value 1026048 Last sector, +sectors or +size{K,M,G} (1026048-31457279, default 31457279): +500M Partition 2 of type Linux and of size 500 MiB is set
- 将分区类型设置为 LVM:
Command (m for help): t Partition number (1,2, default 2): *Enter* Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'
- 当您确定更改正确时,使用 w 选项写入更改,因为错误可能会导致所选分区不稳定。
- 在设备上运行 e2fsck 来检查一致性:
#
e2fsck /dev/vda e2fsck 1.41.12 (17-May-2010) Pass 1:Checking inodes, blocks, and sizes Pass 2:Checking directory structure Pass 3:Checking directory connectivity Pass 4:Checking reference counts Pass 5:Checking group summary information ext4-1:11/131072 files (0.0% non-contiguous),27050/524128 blocks - 挂载该设备:
#
mount /dev/vda
如需更多信息,请参阅 fdisk(8) 手册页。