Resize vm disk size online on proxmox hypervisor

In some cases you can't just power off the virtual machine to increase disk size on it, because, for example, a service is not yet HA configured but needs to be online 24/7, and root partition, doesn't have much space left on it. In such cases you have to increase the disk size on the fly.

Here we are going to explain how that works under Proxmox hypervisor.

ssh me@proxmox.local.int

ssh into proxmox node, where the vm is running.

sudo -s

get our privileged user:

qm list | grep running
> >102 resizevm.local.int running    2048               0.00 314395

get running vms

Ok, virtual machine with ID of 102 is now running.

qm config 102 | grep vm-102-disk | awk -F ":" '{print $1}'
> > scsi0
qm config 102 | grep vm-102-disk | awk -F "," '{print $NF}'
> > size=14G

Get bus controller and size of the disk.

Good so far, lets get the disk size from the vm itself:

ssh me@resizevm.local.int -t "sudo fdisk -l /dev/sda | head -1"
> > Disk /dev/sda: 14 GiB, 15032385536 bytes, 29360128 sectors
> > Connection to resizevm.local.int closed.

So we checked the disk size of the vm from the proxmox and from the vm itself. Got the same result, which is good ).

Let's resize the disk on hypervisor first:

qm resize 102 scsi0 +5G
qm config 102 | grep vm-102-disk | awk -F "," '{print $NF}'
> > size=19G

After we successfully increased the disk size of vm by 5G, we are going to proceed further on vm:

df -hT /
> > Filesystem     Type  Size  Used Avail Use% Mounted on
> > /dev/sda1      ext4   14G  2.2G   11G  17% /

Checking the size again

fdisk -l /dev/sda
> > Disk /dev/sda: 19 GiB, 20401094656 bytes, 39845888 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: 0x6c9d0a72
> >
> > Device     Boot Start      End  Sectors Size Id Type
> > /dev/sda1        2048 29360127 29358080  14G 83 Linux

Good, disk has 19G of storage, but partition needs to be expanded. Hence, we are switching into fdisk utility to increase the partition:

fdisk /dev/sda
> > Welcome to fdisk (util-linux 2.36.1).
> > Changes will remain in memory only, until you decide to write them.
> > Be careful before using the write command.

Deleting partition first

> > Command (m for help): d
> > Selected partition 1
> > Partition 1 has been deleted.

Creating new partition with default values.

> > Command (m for help): n
> > Partition type
> >    p   primary (0 primary, 0 extended, 4 free)
> >    e   extended (container for logical partitions)
> > Select (default p): p

On my system i have only one partition. So i am just recreating one. You probably could have multiple partitions, here you have to re-create all of them. I case of one partition we just hit Enter through the next questions until it asks us to remove the signature....

> > Partition number (1-4, default 1):
> > First sector (2048-39845887, default 2048):
> > Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-39845887, default 39845887):
> > 
> > Created a new partition 1 of type 'Linux' and of size 19 GiB.
> > Partition #1 contains a ext4 signature.

The filesystem on previously deleted partition is signed as ext4 filesystem, fdisk utility sees this marker and asks us if we want to remove it. Here we choose NO, otherwise filesystem will be destroyed and we lose all the data on it.

> > Do you want to remove the signature? [Y]es/[N]o: N

Ensure partition got created with a new size of disk:

> > Command (m for help): p
> > 
> > Disk /dev/sda: 19 GiB, 20401094656 bytes, 39845888 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: 0x6c9d0a72
> > 
> > Device     Boot Start      End  Sectors Size Id Type
> > /dev/sda1        2048 39845887 39843840  19G 83 Linux

Saving results with "w":

> > Command (m for help): w
> > The partition table has been altered.
> > Syncing disks.

No, after we recreated partition with a new size, we need to expand the filesystem on that partition.

resize2fs /dev/sda1
> > resize2fs 1.46.2 (28-Feb-2021)
> > Filesystem at /dev/sda1 is mounted on /; on-line resizing required
> > old_desc_blocks = 2, new_desc_blocks = 3
> > The filesystem on /dev/sda1 is now 4980480 (4k) blocks long.

And re-check the storage size:

df -hT /
> > Filesystem     Type  Size  Used Avail Use% Mounted on
> > /dev/sda1      ext4   19G  2.2G   16G  13% /

And now we see, that we have a new size of our disk: was 14G - got 19G.

Previous Post

Blog Comments powered by Disqus.