On our Proxmox cluster we have configured an NFS server on a VM, and for that we have used three virtual disks:
- A 3 GB virtual disk using QCOW2 format, on our
localstorage, for the OS, which we formatted using EXT4. - A 1 GB virtual disk using RAW format, on our
localstorage, for the swap. - A 100 GB virtual disk using a block device (ZVOL), on our
zfspoolstorage, for the data, mounted on/srv/nfs.
Inside the VM, these disk correspond to /dev/sda, /dev/sdb and /dev/sdc, respectively, and are mounted using UUID in the /etc/fstab file.
Eventually, the time to extend a disk will come. Extending a ZFS volume differs from extending a virtual disk in qcow2 or raw format. Moreover, having a partition table will involve partition math.
ZFS volume #
To extend the ZVOL holding the data disk, follow these steps:
- Resize the disk image or block device.
- Resize the filesystem inside the VM.
To perform the first step, you can either use the WebGUI or the terminal. If you prefer the former, go to the Hardware menu option of the VM, select the data disk and use the Disk action > Resize button, input the number of extra gigabytes you need and click Resize disk. If you prefer the latter, execute the following command from the terminal of the host (adapt the value to your needs):
zfs set volsize=+100G zfspool/vm-104-disk-0
After resizing the disk, use lsblk to check that the OS has already detected the new size. If it does not show the new size, use the following command to instruct the OS to rescan the block device:
echo 1 > /sys/class/block/sdc/device/rescan
To perform the second step you need to use the VM console:
xfs_growfs /dev/sdc
Make sure the disk is mounted before running
xfs_growfs.
XFS supports online resizing, while mounted and even while actively being used. However, if the disk is under heavy load, you might want to temporarily reduce I/O to avoid unpredictable behaviour.
OS disk #
To extend the size of your OS disk (a virtual disk using QCOW2 format), follow these steps:
- Resize the virtual disk using the Proxmox CLI (or GUI, if you prefer).
- Grow the partition.
- Resize the filesystem inside the VM.
First of all, start by installing growpart, the tool of choice for resizing mounted disks when no LVM is involved:
apt-get install --yes cloud-guest-utils
In Debian, the
growpartcommand is part of thecloud-guest-utilspackage, which is pre-installed on cloud images but not on ISO Netinst images.
Use the terminal of the host to execute the following command (adapt the value to your needs):
qm resize 104 scsi0 +1G
If you check the kernel messages using dmesg, you will notice the following messages (numbers will vary depending on your previous size and how much space you added):
sd 0:0:0:0: Capacity data has changed
sd 0:0:0:0: [sda] 8388608 512-byte logical blocks: (4.29 GB/4.00 GiB)
sda: detected capacity change from 6291456 to 8388608
If you now log into the VM via SSH, you can use lsblk to realise that the new disk size has already been caught up by the kernel. However, the /dev/sda1 partition still shows the old size:
# lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 4G 0 disk
├─sda1 8:1 0 2.9G 0 part /
├─sda14 8:14 0 3M 0 part
└─sda15 8:15 0 124M 0 part /boot/efi
Use growpart in the console of the VM to resize the partition:
growpart /dev/sda 1
We can now see the changes in the partition using lsblk:
# lsblk /dev/sdb
sda 8:0 0 4G 0 disk
├─sda1 8:1 0 3.9G 0 part /
├─sda14 8:14 0 3M 0 part
└─sda15 8:15 0 124M 0 part /boot/efi
However, the filesystem still shows the previous value:
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2.8G 2.0G 629M 77% /
Therefore, all that is left is to use the EXT4 resizer to resize the filesystem:
resize2fs /dev/sda1
And verify the results:
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.8G 2.0G 1.6G 57% /
You can also perform the procedure using
fdiskandsfdisk, but it is more error-prone and cannot be automated.
Swap disk #
Resizing a swap disk can be simpler than resizing an OS or data partition because swap does not have a traditional filesystem. Furthermore, we do not need to preserve data.
To extend the size of your swap disk (a virtual disk using RAW format), follow these steps:
- Resize the virtual disk in Proxmox GUI or CLI.
- Turn off swap temporarily
- Make the new swap area.
- Enable swap again.
Use the WebGUI or the terminal to extend the disk. If you prefer the former, use the Hardware > Disk action > Resize button on the appropriate disk (e.g., SCSI-1), set the additional size in gigabytes and confirm. If you prefer the latter, execute the following command from the terminal of the host (adapt the value to your needs):
qm resize 104 scsi1 +1G
Inside the VM, turn off swap temporarily:
swapoff -a
Now make a new swap area:
mkswap /dev/sdb
And enable swap again:
swapon /dev/sdb
Optionally, ensure /etc/fstab is still pointing at the correct UUID:
swapon --show