Howto resize a libvirt (kvm/qemu) disk image
I’m using kvm for a while at work. Everything works quite fine, but today I needed to grow a disk image. I found some informations, but none are really clear so here the result :
First create a empty image file .. with this command (don’t use dd, qemu-img is really quicker than dd):
qemu-img create -f raw temp.img 10G
Next simply your image file + the temp one, in a biggest one ..
cat foo.img temp.img > bar.img
You will get a new image file which is 10G bigger than the original one .. Now you can boot your OS, and discover (via cfdisk for example), that your system has a additionnal 10G unused space .. So next step:
- Just create a new partition, and mount it in the normal way
- Boot your kvm OS from a ISO file containing Gparted
I tried the second approach, and used a ubuntu install to boot (using virt-manager, this is really easy to do). And resized the partition to my need .. simply reboot and “tada” :)
Enjoy disk ?
- Howto reinstall / restore Grub with an Ubuntu
- Linux APM (Suspend to disc) on a Dell Inspiron / Latitude
- Suspend to disc with Dell Latitude D400 on Linux
- Grub install on Debian Howto
- Installing Debian on a Dell Latitude D400
admin April 28th, 2009
- Utils
- Comments(4)
Can you do it faster by replacing the second step with
cat temp.img >> foo.img
?
Can you do it even faster by enlarging the first file in-place with
dd if=/dev/null of=foo.img bs=1b seek=20G count=0
(in this case the 20G is the new total size, not the increment!)?
For Marius:
cat temp.img >> foo.img
Yes, you can do this, but this would delete the backup too ..
For the second way, I don’t think this will work because enlarge it with /dev/zero (not null, i think).. and this not a valid partition..
Bye
Great post.Thanks alot..That article helps me out.Before i had some problems with it.
Greetings from Germany
Much faster way, using dd:
dd if=/dev/zero of=foo.img bs=1 count=1 seek=$(($(stat -c%s foo.img)+10*1024**3-1))
Obviously your method (and this) only work when dealing with raw images.