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
Online Method (using qemu, libvirt, and virtio-block)
Perform the following from the KVM hypervisor.
Then log into the VM. Running
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
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.
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
Another way to do it
go in the make a disk rescan and after you can do your lvm resize.
Resize and Expand Internal Partitions in One Step
I had an Ubuntu host with a qcow2 guest file image and wanted to resize the disk and expand the appropriate partitions all in one step. It requires you to set up the libvirt guest filesystem utilities, but those are useful to have around anyway.
Inspiration from here: http://libguestfs.org/virt-resize.1.html
The key command here is:
Now do the following:
1) shutdown the guest:
2) Check out the current sizing and view the partition name you want to expand using libvirt utility:
3) Create the new (40G) output disk:
4) Copy the old to the new while expand the appropriate partition (assuming your disk partition from step 2 was /dev/sda1):
5) Rename the indisk file as a backup, rename the outdisk as indisk (or modify the guest XML)
6) Reboot the guest and test the new disk file carefully before deleting the original file