wiki:extend-disk-on-kvm-guest

Version 1 (modified by Jamie McClelland, 13 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 (is there a way around this??).

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

cat /proc/partitions

You should see that the base disk (e.g. /dev/sda), although all of the partitions are the same size.

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

parted /dev/sda
unit s
p

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

mkpart primary STARTSECTOR ENDSECTOR

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):

rm 2
mkpart primary STARTSECTOR ENDSECTOR

When creating new partitions, it's a good idea to ensure that the total size of the sector is divisible by 4096.

Note: See TracWiki for help on using the wiki.