| | 1 | = How do I extend the disk space for a KVM guest? = |
| | 2 | |
| | 3 | Our KVM guests are each allocated a single logical volume from the KVM host's volume group (typically named after the host). |
| | 4 | |
| | 5 | The first and easiest step is to login to the host, check available disk space, and then run the lvextend command: |
| | 6 | |
| | 7 | {{{ |
| | 8 | 0 ken:~# vgs |
| | 9 | VG #PV #LV #SN Attr VSize VFree |
| | 10 | vg_ken0 1 16 0 wz--n- 1.82t 1.29t |
| | 11 | 0 ken:~# lvs | grep mirabal |
| | 12 | mirabal vg_ken0 -wi-ao 20.00g |
| | 13 | 0 ken:~# lvextend --size 35G vg_ken0/mirabal |
| | 14 | Extending logical volume mirabal to 35.00 GiB |
| | 15 | Logical volume mirabal successfully resized |
| | 16 | 0 ken:~# |
| | 17 | }}} |
| | 18 | |
| | 19 | 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??). |
| | 20 | |
| | 21 | After rebooting, you can confirm the new size by running: |
| | 22 | |
| | 23 | {{{ |
| | 24 | cat /proc/partitions |
| | 25 | }}} |
| | 26 | |
| | 27 | You should see that the base disk (e.g. /dev/sda), although all of the partitions are the same size. |
| | 28 | |
| | 29 | Next, run parted and print the current partition table. It's often easier to manage if you look at units in sectors: |
| | 30 | |
| | 31 | {{{ |
| | 32 | parted /dev/sda |
| | 33 | unit s |
| | 34 | p |
| | 35 | }}} |
| | 36 | |
| | 37 | You can optionally create a new partition with the remaining space: |
| | 38 | |
| | 39 | {{{ |
| | 40 | mkpart primary STARTSECTOR ENDSECTOR |
| | 41 | }}} |
| | 42 | |
| | 43 | 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): |
| | 44 | |
| | 45 | {{{ |
| | 46 | rm 2 |
| | 47 | mkpart primary STARTSECTOR ENDSECTOR |
| | 48 | }}} |
| | 49 | |
| | 50 | When creating new partitions, it's a good idea to ensure that the total size of the sector is divisible by 4096. |