Howto: Resize Xen Loop Disk Image

Win4lin, KVM, QEMU, Virtualbox and Xen are all widely used technologies, used in virtual servers. Fairly often a virtual server run from within a loop filesystem and generally start with a fairly small file (1GB is big for a normal file, but not when it is pretending to be an entire filesystem!)

However things often grow over time.

Here is a nice simple procedure for increasing the size of a loop filesystem, if the filesystem is ext2 or ext3 (the procedure should work for ext4 too, but I havn’t tested it yet)

1. Stop the virtual server that is using the loop filesystem
2. Add some extra space to your loop filesystem file
# dd if=/dev/zero bs=1024k count=1024 >> loop_image_file

This adds 1GB to the end of a file called loop_image_file (make sure to use the append output redirector >> not a single >, otherwise you’ll have an empty 1GB file!)

3. Force a check on the resized/increased filesystem
# e2fsck -f loop_image_file

4. Resize the filesystem within the loop filesystem file
# resize2fs loop_image_file

5. Start the virtual server again

Comments off