I need to extend the root partition of a virtual machine (VM) using LVM (Logical Volume Manager). I can afford a few minutes of downtime so a VM shutdown/reboot is fine.

The virtual hard disk is in qcow2 format but I can translate it to a raw format easily.

Search engines did not help that much because answers usually refer to using a LVM partition to host the virtual hard disk, here the LVM partition is inside the virtual hard disk which is a simple file.

The virtual machine is running with linux-kvm and must stay bootable after the operation.

1 Answer 1


Your safest pick, without the need of making any changes to your current qcow disk, is adding another disk to the VM. Once you have rebooted, you can run these commands:

  1. pvcreate /dev/${newdisk}
  2. vgextend ${vgname} /dev/${newdisk}
  3. lvextend -L +${n}G /dev/${vgname}/${root_lv} (+ means add to LV ${n} GBs)
  4. resize2fs /dev/${vgname}/${root_lv}

In the end you get extra room on / with just a reboot.

  • can I do resize2fs on '/' within the running VM ?
    – ascobol
    Feb 13, 2012 at 9:59
  • 2
    You can. "resize2fs" can enlarge a mounted partition, and shrink an unmounted one. "/" is no exception.
    – katriel
    Feb 13, 2012 at 10:27
  • do NOT attempt to enlarge the root partition of the guest while the guest is running by issuing resize2fs on the host. If the filesystem is mounted, it should be enlarged only by the system that has it mounted. This is also true when the LVM volume group is active, it should only be modified on the guest that has it active. perform these steps on the guest and all will be well. Mar 6, 2012 at 16:39
  • You are right of course. All the above steps should be done inside the VM.
    – katriel
    Mar 8, 2012 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .