An installed KVM Ubuntu 10.04 guest with regular disk using LVM (lvm makes the resize operation a bit more tricky).
In this example the original disk was 20 GB and I want to extend it with 20GB more.
- Stop guest
- Extend imagefile med zeroes to desired size
- create addon space with the size you want to extend disk with
sudo qemu-img create -f raw addon.raw 20G
- make backup of the original disk
mv ubuntu-dev.img ubuntu-dev.img.save
- concatenate the extra space on top of the old image
cat ubuntu-dev.img.save addon.raw >> ubuntu-dev.img - Start guest with gparted live iso
Partitions might look like:Number Start End Size Type File system Flags
1 1049kB 256MB 255MB primary ext2 boot
2 257MB 20.5GB 20.3GB extended
5 257MB 20.5GB 20.3GB logical lvm
- extend physical partition (2) with gparted (easiest) to fill upp the entire (new) disk - Reboot into guest
- Remove the logical partition (lvm)
- Create a new logic partition, with exact same start but new ending
rm 5; mkpart logical ext2 0 4000; set 5 lvm on - Resize the lvm physical volume (use pvdisplay to find out the device /dev/vda5)
- pvresize /dev/vda5 - Resize the lvm locial volume
- lvresize -L+4309 /dev/www/root
repeat the above until you fill up the entire free space, use pvdisplay and lvdisplay to see the free size - fsck the filesystem, the filesystem name is visible when you do lvdisplay
- fsck -n /dev/www/root - Resize the filesystem to fill up the space
- resize2fs /dev/www/root