如何在线扩容磁盘块设备分区?
- By : Will
- Category : Virtualization

Virtualization
1 前言
一个问题,一篇文章,一出故事。
笔者今天需要在Proxmox Virtual Enviroment环境中,如果执行底层的VM磁盘扩容,则会VM进入系统后,会出现两个问题,
GPT PMBR大小不匹配问题,此问题的解决方案请参阅,
另外一个问题就是分区比实际的磁盘要小,因此真是空间得不到利用,你可以考虑把创建一个新的分区利用新增加的空间,但是也可以选择按本章的方法直接扩展该分区。
2 最佳实践
2.1 部署PVE环境
关于PEV环境,如有需要请参阅,
2.2 在线扩容跟分区
2.2.1 查看当前的分区
fdisk -l
可见如下显示,
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors Disk model: QEMU HARDDISK 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: gpt Disk identifier: CD0D6008-AE71-21D7-C817-D7010558E800 Device Start End Sectors Size Type /dev/sda1 512 33279 32768 16M Linux filesystem /dev/sda2 33280 246271 212992 104M Linux filesystem /dev/sda128 34 511 478 239K BIOS boot Partition table entries are not in disk order.
注:当前“/dev/sda”识别到是32GB的磁盘,但是“/dev/sda2”非常小。
2.2.2 在线扩容分区
parted -f -s /dev/sda resizepart 2 100%
以上是快速指令,如果你喜欢使用向导操作,请按如下向导执行,
parted /dev/sda
按照如下向导操作,
GNU Parted 3.6 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: QEMU QEMU HARDDISK (scsi) Disk /dev/sda: 34.4GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 128 17.4kB 262kB 245kB bios_grub 1 262kB 17.0MB 16.8MB fat16 legacy_boot 2 17.0MB 126MB 109MB ext4 (parted) resizepart 2 End? [126MB]? 100% (parted) print Model: QEMU QEMU HARDDISK (scsi) Disk /dev/sda: 34.4GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 128 17.4kB 262kB 245kB bios_grub 1 262kB 17.0MB 16.8MB fat16 legacy_boot 2 17.0MB 34.4GB 34.3GB ext4 (parted) quit Information: You may need to update /etc/fstab.
没有评论