在proxmox中调整磁盘容量

pve直接提供了网页接口,因此在网页中调整vm硬盘即可。注意文件系统应为LVM。

在虚拟机中进行容量叠加

首先reboot,然后看到出现新的未分配空间。未调整前大小为29GB:

Disk /dev/sda: 29 GiB, 31138512896 bytes, 60817408 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: dos
Disk identifier: 0xedaaada3

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048   499711   497664  243M 83 Linux
/dev/sda2         501758 56621055 56119298 26.8G  5 Extended
/dev/sda3       56621056 60817407  4196352    2G 83 Linux
/dev/sda5         501760 56621055 56119296 26.8G 8e Linux LVM

Partition table entries are not in disk order.


Disk /dev/mapper/debian--vg-root: 26.3 GiB, 28198305792 bytes, 55074816 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 /dev/mapper/debian--vg-swap_1: 508 MiB, 532676608 bytes, 1040384 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

这里增加了2GB后的效果:

root@debian:~# fdisk -l
Disk /dev/sda: 31 GiB, 33285996544 bytes, 65011712 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: dos
Disk identifier: 0xedaaada3

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048   499711   497664  243M 83 Linux
/dev/sda2         501758 56621055 56119298 26.8G  5 Extended
/dev/sda3       56621056 60817407  4196352    2G 8e Linux LVM
/dev/sda5         501760 56621055 56119296 26.8G 8e Linux LVM

Partition table entries are not in disk order.


Disk /dev/mapper/debian--vg-root: 28.3 GiB, 30345789440 bytes, 59269120 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 /dev/mapper/debian--vg-swap_1: 508 MiB, 532676608 bytes, 1040384 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

接着使用cfdisk进行分区操作,界面比fdisk简单,直观:
cfdisk.PNG
可以看到绿色区域free space就是新添加的容量。这里选中free space
cfdsik2.PNG
选择New回车,再选择空间(或者直接回车)后就已建立好新分区,再选择Type,在分区类型处选择Linux LVM:
cfdsik3.PNG
选择好分区类型后,在上一层选择Write将修改写入即可。
如此一来分区就建好了,接下来将其与主分区合并:

  1. 将物理硬盘分区初始化为物理卷,以便LVM使用
     root@debian:~# pvcreate -ff /dev/sda4
     Physical volume "/dev/sda4" successfully created.
    
  2. 创建LVM卷组,此处 amfslvm3 为卷组名,可随意命名
     root@debian:~# vgcreate amfslvm3 /dev/sda4
     Volume group "amfslvm3" successfully created
    
  3. 列出当前所有卷组,可以看到debian-vg就是主卷组
     root@debian:~# vgscan
     Reading all physical volumes.  This may take a while...
     Found volume group "amfslvm3" using metadata type lvm2
     Found volume group "debian-vg" using metadata type lvm2
    
  4. 将新创建卷组与主卷组合并
     root@debian:~# vgmerge debian-vg amfslvm3
     Volume group "amfslvm3" successfully merged into "debian-vg"
    
  5. 使用空闲容量扩充主卷组,此处/dev/mapper/debian—vg-root 需要自己使用 df -h查看
     root@debian:~# lvresize --extents +100%FREE --resizefs /dev/mapper/debian--vg-root
     Size of logical volume debian-vg/root changed from 28.26 GiB (7235 extents) to <30.26 GiB (7746 extents).
     Logical volume debian-vg/root successfully resized.
     resize2fs 1.44.5 (15-Dec-2018)
     Filesystem at /dev/mapper/debian--vg-root is mounted on /; on-line resizing required
     old_desc_blocks = 4, new_desc_blocks = 4
     The filesystem on /dev/mapper/debian--vg-root is now 7931904 (4k) blocks long.
    
  6. 验证是否生效
     root@debian:~# df -h
     Filesystem                   Size  Used Avail Use% Mounted on
     udev                         226M     0  226M   0% /dev
     tmpfs                         49M  2.3M   47M   5% /run
     /dev/mapper/debian--vg-root   30G 1021M   28G   4% /
     tmpfs                        242M     0  242M   0% /dev/shm
     tmpfs                        5.0M     0  5.0M   0% /run/lock
     tmpfs                        242M     0  242M   0% /sys/fs/cgroup
     /dev/sda1                    236M   49M  176M  22% /boot
     tmpfs                         49M     0   49M   0% /run/user/0