I setup an Ubuntu guest on a CentOS KVM host with initially 6GB of disk space. How do I go about increasing the Ubuntu guest's disk space from the command line?
EDIT #1: I'm using a disk image file (qemu).
These serverfault questions are similar but more specific, KVM online disk resize? & Centos Xen resizing DomU partition and volume group. The 1st asks the question of how to increase a KVM guest while it's online, while the 2nd is XEN specific using LVM. I'm asking how to accomplish this while the KVM is offline.
NOTE: This link was useful for METHOD #1, and shows how to accomplish increasing a KVM's disk space (ext3 based), HOWTO: Resize a KVM Virtual Machine Image.
One thing to be aware of with KVM guests is that the partitions they're using inside can effect which method you can use to increase their disk space.
METHOD #1: Partitions are ext2/ext3/ext4 based
The nuts of this method are as follows:
Now with the larger mykvm.img file in hand, boot gparted and extend the existing partition into the newly added disk space. This last step basically extends the OS partition so that it can make use of the extra space.
METHOD #2: Partitions are LVM based
Here are the steps that I roughly followed to resize a KVM guest that used LVM internally.
The above is my example, but I followed the steps on this website
If you are using LVM within the VM the simplest way to do this woudl be to add a new virtual disk to the VM and expand the volume group and logical volumes onto that.
To check if you are using LVM run
if the VM's OS is using LVM. In the above example the VM has a 30Gbyte vdisk, configured using LVM with one volume group called vgWWW containing two logical volumes, one for swap and one for everything else.
If LV is in use in the VM:
Note: the above assumes the vg/lv names are the same as my example which is unlikely, change as appropriate, also if the VM already had a virtual drive called
Note: as you are resizing a live filesystem
An othere way to do it
truncate -s +2G vm1.img
go in the make a disk rescan and after you can do your lvm resize
If you have LVM in your VM then this is crazy easy and fast.
I found the GUI quite intuitive, but follow next steps if you have problems.
Note! At least on CentOS 6 LVM GUI is not installed by default, but you can install it with
There is a possibility to increase the size of your VM's disk without rebooting the VM if you're using virtio drive and LVM.