Extend the system partition in a Windows virtual machine running within kvm/lvm

You have that Windows 7 or Windows XP virtual machine and you are running short of system disk size. So you wish to extend it without rebuilding the virtual machine and with no risks ?

The following applies if the virtual machine is running under kvm version 0.12.5 or later, with the system disk being a virtualized volume using linux Logical Volume Manager (LVM).

First of all stay clear of any howto suggesting to access the NTFS partitions from the host operating system !

Do this instead:

  1. Find out what is the virtual volume the virtual machine is attached to

    # grep lv /etc/libvirt/qemu/name_of_virtual_machine.xml
    <source dev='/dev/vg0/lv11'>
  2. Query the status of the virtual volume

    lv11 vg0 -wi-ao 30,00g
  3. Shut down the virtual machine

  4. Query again the status of the virtual volume; notice the “o” (open) has disappeared

    # lvs | grep lv11
    lv11 vg0 -wi-a- 30,00g
  5. Resize the virtual volume

    # lvextend --size +10G vg0/lv11
  6. Query once more the status of the virtual volume; notice the size has been increased

    # lvs | grep lv11
    lv11 vg0 -wi-a- 40,00g
  7. Extend the disk using the guest operating system specific tool.

To do that with Windows 7, just restart the virtual machine then from within disk manager use the extend command (should require no reboot).

With Windows XP, the tool is diskpart but it does not work for system or boot volumes and if the system page file is located on the partition you want to extend. Workaround: attach (as SCSI or as IDE, may require a reboot) the virtual disk you need to manipulate from a different virtual machine running the same operating system:

then run diskpart from this virtual machine, extend the partition in the freshly attached volume:

finally detach the volume from the second machine, and restart the first virtual machine.

Done !