Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 if it helps.

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.

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
can I do resize2fs on '/' within the running VM ? – ascobol Feb 13 '12 at 9:59
You can. "resize2fs" can enlarge a mounted partition, and shrink an unmounted one. "/" is no exception. – katriel Feb 13 '12 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. – SingleNegationElimination Mar 6 '12 at 16:39
You are right of course. All the above steps should be done inside the VM. – katriel Mar 8 '12 at 11:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.