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
Related posts:
- Migrate existing Ext3 filesystems to Ext4
- Xen Howto: Install Windows
- Howto: How to Reset the MySQL Root Password
- Howto Install Windows XP / Vista on Xen
- How to mount bin / cue image files in Linux
- Ubuntu Howto: Install Xen
- How to Mount a Remote Filesystem Using SSH and sshfs
- Importing / Exporting Virtual Disk Images with Virtual Box
- Installing Xen on Debian Etch 4.0
- Ubuntu Server Edition JeOS
Popular Related Items »
Incoming search terms
- xen extend disk image
- Resize xen image
- xen resize disk image
- grow xen image
- xen expand disk image
- xen grow disk image
- xen resize
- xen loop
- xen disk image
- extend xen disk
- extend xen image
- resize xen disk image
- shrink xen disk image
- xen expand disk
- xen grow image
- xen resize disk
- xen resize image
- xenserver resize disk
- xen extend disk
- xenserver resize virtual disk
- extending disk in xen
- resize dd image
- xen disk resize
- Xen disk size
- xen grow disk
- xen image resize
- xen shrink virtual disk
- xen virtual disk resize
- expand xen image
- resize xen disk
- shrink dd image
- xen shrink
- xenserver shrink virtual disk
- dd loop xen
- expand xen disk image
- resize xen virtual disk
- resize xen windows image
- shrink xen image
- xen extend image size
- xen extending disk
- xen resize guest image
- xen resize virtual disk
- xen shrink image
- xen virtual disk image

Expanding xen disk file image « Thomas Mathiesen’s Blog said,
May 10, 2009 @ 14:12
[...] virtual machine (guest), it’s quite easy to expand the image file. I stole this receipt from here, just to make sure that I have a copy in case his/her website goes [...]
Ciprian Pantea said,
June 7, 2009 @ 10:10
(lol at the spam protection system
)))))
thanks for the tip, is there a way to shrink the partitions? also what partition type is the best used when using xen? reiser, xfs, ext2, ext3?
Ryan Bushby said,
August 12, 2009 @ 19:47
Ciprian Pantea, to shrink a partition you need to first run resize2fs to set the filesystem to a smaller size, then afterwards you need to truncate the loop file to that size.
I am not sure on the correct way to truncate the file, however I would suggest leaving a bit of room at the end unless you are certain about your math.
Imran Chaudhry said,
August 18, 2009 @ 15:41
To resize a Xen guest filesystem that exists as a loopback file:
1. ensure the guest is not running
2. make a copy of the file to resize, just in case (ensure you have sufficient free space first). Lets say the file is disk.img, backup is disk.img-backup
3. as root, run resize2fs – it may prompt you to run “e2fsck -f disk.img” – if it does then do so.
4. do the resize resize2fs disk.img 3G
5. confirm the size with du -h disk.img
6. now start up the xen guest and confirm the size is ok from within the guest: df -h
Imran Chaudhry said,
August 18, 2009 @ 15:50
Forgot to mention, the above was done with a Debian Lenny Xen host and Etch guest. It was a shrink action as I wanted to reclaim space on the Xen host.
I expected to have to use dd to physically resize the file from 4 to something just over 3.1 but resize2fs appears to have catered for this. This seems to be at variance with the man page.