This post will set out to explain how you can increase the disk size of a virtual disk inside a VM after increasing its size in your hypervisor. It does assume some familiarity with Linux and partitioning.

Its is mainly aimed at CentOS and Debian. Though this should also be relevant if you are using the same disk technologies. Those being LVM+XFS for the CentOS and plain ext4 for Debian.

CentOS

This assumes a fairly standard CentOS install that uses LVM and XFS.

TL;DR

1
2
3
4
sudo cfdisk
sudo pvresize /dev/sda3
sudo lvextend -l 100%FREE /dev/mapper/cl-root
sudo xfs_growfs /

Step 0: Hypervisor

Before doing this make sure you have expanded the disk to the desired size in your hypervisor of choice (eg. within proxmox).

Step 1: Increase partition

Now increase the size of the root partition using something like fdisk or cfdisk. If your root partition is not the last partition this would also entail removing and re-creating your swap partition, for information on how to do that I’ll refer to the arch wiki.

Step 2: Resize Physical Volume

Now that the partition is expanded you should expand the accompanying LVM Physical Volume as follows:

1
pvresize /dev/sda3

Where /dev/sda3 is the partition you expanded in step 1.

For more information on pvresize see its man page

Step 3: Extend Logical Volume

Now that the PV has been resized you can resize the LVM Logical Volume with lvextend like so:

1
lvextend -l 100%FREE /dev/mapper/cl-root

In this command the 100%FREE refers to all remaing space of the PV and the /dev/mapper/cl-root should be the location of your root volume; which you can check with lsblk if uncertain.

Again you can check its man page for any more information.

Step 4: Grow XFS

Finally we need to expand the actual XFS filesystem, this is fairly easy luckily:

1
xfs_growfs /

xfs_growfs takes the mountpoint of the filesystem as its argument, which is / in this case.

Debian

This assumes a fairly standard Debian install that uses ext4.

TL;DR

1
2
3
sudo cfdisk
sudo partprobe /dev/sda
sudo resize2fs /dev/sda5

Step 0: Hypervisor

Before doing this make sure you have expanded the disk to the desired size in your hypervisor of choice (eg. within proxmox).

Step 1: Recreate Partitions

Now increase the size of the root partition using something like fdisk or cfdisk. Debian uses something called “Extended Partitions” by default which makes this a bit more difficult. Instead of simply resizing the partition you need to:

  1. Note down the starting sector of the extended partition
  2. Remove the extended partion
  3. Recreate the extended partition now using full available size
  4. Recreate the root partition

If you have any swap in the extended partition or after it you would need to recreate this as well. Some information with regards to swap can be found on the arch wiki.

Step 2: Partprobe

Now we need to use partprobe the disk to make debian aware of the size change. This is simply just doing:

1
sudo partprobe /dev/sda

where /dev/sda the disk which you expanded.

Step 3: Resize filesystem

Finally you can resize the actual filesystem on the disk’s partition with resize2fs like so:

1
sudo resize2fs /dev/sda5

where /dev/sda5 is the root partition.


Appendix

Some useful notes that aren’t necessarily part of the rest of this how-to.

LVM Debugging

If LVM for some reason does not like to behave these commands may come in useful:

Listing all Logical Volumes
lvs

Getting information about a specific Physical Volume
pvdisplay /dev/sda2 -m