我的希望将PVE中的虚拟机磁盘调整一下,增加20GB。在查询了一些资料后,做一下总结教程。
环境是 PVE8.2.2 版本,虚拟机系统是centos7.9.2009-minimal, 安装系统时划分磁盘分区方式是默认分区方式(不同分区方式下,扩展磁盘大小的操作步骤可能不相同)。
第1步
先将虚拟机关机状态
第2步
在PVE管理平台,调整虚拟机磁盘大小.
我这里需要添加20GB。
第3步
启动虚拟机
第4步
进入虚拟机系统,查看系统的分区信息,磁盘信息。可以发现,磁盘的总大小变了,但是分区没变。所以我们接下来的工作,是调整分区大小。
第5步
我希望将将剩余空间加在sda3上。这里可以根据实际需要调整。
[root@localhost ~]# parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? Fix
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 41943040 blocks) or continue with the current setting?
Fix/Ignore? Fix
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags1 1049kB 211MB 210MB fat16 EFI System Partition boot2 211MB 1285MB 1074MB xfs3 1285MB 42.9GB 41.7GB lvm(parted) resizepart 3 100%
(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags1 1049kB 211MB 210MB fat16 EFI System Partition boot2 211MB 1285MB 1074MB xfs3 1285MB 64.4GB 63.1GB lvm(parted) quit
Information: You may need to update /etc/fstab.[root@localhost ~]#
如果出现类似如下的提示:直接输入Fix 修复即可。
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel?Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 41943040 blocks) or continue with the current setting?
Fix/Ignore? Fix
第6步
更新物理卷 和 逻辑卷大小
[root@localhost ~]# pvresize /dev/sda3
[root@localhost ~]# lvresize --extents +100%FREE --resizefs /dev/mapper/centos-root# 此处的参数可以根据实际需要调整
第7步
验证是否生效。通过命令查看,发现已经生效。