Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 (read: google) 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.

Thanks for any hints.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Your safest bet, not needing any changes to your current qcow disk, is adding an additional disk to the VM. Once you've rebooted, you could:

  1. pvcreate /dev/newdisk
  2. vgextend [vgname] /dev/newdisk
  3. lvextend -L +[#]G /dev/[vgname]/[root lv] (+ means add to current LV)
  4. resize2fs /dev/[vgname]/[root lv]

So 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
1  
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. –  TokenMacGuy 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
add comment

Your Answer

 
discard

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.