Version 10 (modified by Jamie McClelland, 9 years ago) (diff)


How do I extend the disk space for a KVM guest?

Our KVM guests are each allocated a single logical volume from the KVM host's volume group (typically named after the host).

The first and easiest step is to login to the host, check available disk space, and then run the lvextend command:

0 ken:~# vgs
  VG      #PV #LV #SN Attr   VSize VFree
  vg_ken0   1  16   0 wz--n- 1.82t 1.29t
0 ken:~# lvs | grep mirabal
  mirabal  vg_ken0 -wi-ao  20.00g                                      
0 ken:~# lvextend --size 35G vg_ken0/mirabal
  Extending logical volume mirabal to 35.00 GiB
  Logical volume mirabal successfully resized
0 ken:~#

Next, you will need to reboot the guest before the change in disk space is recognized by the guest (this is apparently a requirement until someone implements online disk resizing). Under kvm-manager, i think that means you need to do a shutdown -h, so that the underlying block devices get reinitialized by a new process.

After rebooting, you can confirm the new size by running:

cat /proc/partitions

You should see that the base disk (e.g. /dev/vda) reflects the new size, although all of the partitions reflect their old sizes (e.g. /dev/vda2).

Next, run parted and print the current partition table. It's often easier to manage if you look at units in sectors:

parted /dev/vda unit s p

You can optionally create a new partition with the remaining space:

parted /dev/vda
unit s
mkpart primary STARTSECTOR -1 

Or, you can delete the last partition, and re-create it with a higher end sector (yes, you can do this without destroying the data on the disk):

unit s
rm 2
mkpart primary STARTSECTOR -1 

When creating new partitions, it's a good idea to ensure that the the disks start on sectors that are multiples of 8192.

Next, check to see if your changes are reflected in /proc/partitions:

cat /proc/partitions

You may need to reboot a second time before they will show up.

Once your partition table is reflecting the new size:

pvresize /dev/vda2

And now your volume group should show additional free space.