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:

  1. Migrate existing Ext3 filesystems to Ext4
  2. Xen Howto: Install Windows
  3. How to mount bin / cue image files in Linux
  4. Howto: How to Reset the MySQL Root Password
  5. Ubuntu Server Edition JeOS
  6. Howto Install Windows XP / Vista on Xen
  7. How to Mount a Remote Filesystem Using SSH and sshfs
  8. Importing / Exporting Virtual Disk Images with Virtual Box
  9. Ubuntu Howto: Install Xen
  10. Virtualization Visualization with Visio

Popular Related Items »

7 Comments »

  1. 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 [...]

  2. 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?

  3. 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.

  4. 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

  5. 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.

  6. Paul ward said,

    June 2, 2010 @ 1:57

    Great advice it worked perfectly on my virtual file system using encfs too. :)
    I can now move files to my encfs folder and grow the virtual file system as I free up space!

  7. Howto: Xen Loop Disk Image vergrössern | Stetix said,

    July 6, 2010 @ 11:59

    [...] ist eine Übersetzung des Original-Posts "Howto: Resize Xen Loop Disk Image". Ähnliche Artikel:Cronjob Linux Tutorial und Crontab [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment