Expand a VM disk in Proxmox (Ubuntu VM)

Disclaimer: this is a very risky operation!
Make sure you have one or more backups of your data!
Use on your own risk!

This tutorial will guide you in increasing the space of your virtual disk. Three steps are required:
1. increase the VM disk size in Proxmox
2. change the partition table to reflect the changes in Ubuntu
3. resize your file system in Ubuntu

1. Resizing VM disk size in Proxmox

1.1 Open the Proxmox webinterface, select the VM for which you want to modify a disk size and select the hardware tab. Write down the VM ID (example: 103) and the harddisk identifier (example: scsi0).

Proxmox: Identify the hard disk identifier (scsi0) and the VM ID (103)

1.2 In the Proxmox VM/LC tree, select the parent node. Open the node shell. Resize the VM size using the following command in the Proxmox node’s shell. This step can be done online (VM running) or offline (VM shut down).

qm resize [VM_ID] [DISK_IDENTIFIER] +[SIZE_INCREASE]G

Example:

qm resize 103 scsi0 +2000G

1.3 Verify that the hardware tab reflects the executed changes in the VM disk size. If you try to add more space than there is available space left on the hard drive, you will get an error (zfs error: cannot set property for ‘vm-103-disk0’: size is greater than available space).

Now that your virtual disk has the desired size, we need to change the partition table so that your Ubuntu will see it.

2. Enlarge the partition in the virtual disk

2.1 Find the disk name of the disk whose partition you want to change inside your VM.

lsblk

My disk (sdb) now has 13.7 TB. You can notice that the partition (sdb1) does not use all the available space yet.

Current partition scheme

2.2 Before unmounting the disk, make sure that no service uses the corresponding disk. In my case, I preferred to shutdown the Apache service to make sure that no user activity intervenes on the disk.

2.3 Unmount all filesystems of the disk on which you want to change the partition table. We want to change the partition table of sdb, so we have to unmount sdb1 (which is the only partition on this disk).

umount /dev/sdb1
Check that the partition has been unmounted (/data should not be listed anymore)

2.4 We will be using fdisk to repartition the disk.

fdisk command options

You can run fdisk -l to list all the partitions available.

Inside fdisk, you can use the following commands:

fdisk commands

Run the following command to start modifying your partition. Make sure to use the disk (sdb) and not the partition name (sdb1)

fdisk /dev/sdb

2.5 Now delete the current partition scheme (that’s scary, isn’t it?) using the “d”-command.

fdisk delete partition

2.6 Create the new partition using the “n” command. We kept the default values and did not remove the ext4 signature.

2.7 Now you need to write the new partition scheme to the disk using the “w” command.

Write the partition scheme

2.8 Now check that the modifications have been saved, using lsblk.

lsblk
lsblk output (the partition shows the full space)

You will notice that the filesystem still does not yet see the whole space that is available. Use df -h.

Output of df -h (the file system does not reflect the whole available space)

So let’s resize the file system inside the partition sdb1.

3. Resize the file system

Run the resize2fs command on the newly created partition.

resize2fs /dev/sdb1
Output of resize2fs /dev/sdb1

df -h now reflects the changes:

output of df -h (the file system now uses all available space)

Additional links

If you need further information on this topic, consult the following webpages:
Proxmox Wiki: Resize disks
How to Increase VM Disk Size in Proxmox
Resize partitions in Linux
Why df and lsblk command have different results?

Leave a Reply