Resizing an ext3 Xen disk image

In: Uncategorized

26 Jun 2009

I’ve seen this a few other places and it didn’t quite work. Let’s say you download a half-gig barebones Linux VM to use with Xen. It runs great, but you want more than 500MB of disk space. Here’s exactly what I had to do:

  • Shut down the virtual machine and make sure nothing is using the disk image!
  • Make a backup of the current image (cp imagefile.img imagefile.img_backup) in case anything goes awry
  • Make a blank file with dd of the size you want to add, e.g., dd if=/dev/zero of=10gig.img bs=1024 count=10000000 for a 10GB image. This may take a bit.
  • Append that to the end of your file, e.g., cat 10gig.img >> imagefile.img
  • “Mount” it as a loopback device: losetup /dev/loop0 imagefile.img
  • Run an fsck, which will find errors, since growing a filesystem this way is bizarre: e2fsck -f /dev/loop0
  • After that completes, resize the filesystem. This may take a while: resize2fs /dev/loop0
  • “Delete” the loopback device (think “unmount”): losetup -d /dev/loop0
  • Start your VM up, and it should now see 10GB extra space!

Related posts:

  1. Disk Throughput
  2. Losing Disk Space on Vista?
  3. Resizing Images and HTML
  4. Finding the Largest Image on a Page
  5. Defragging & Paging Files

Comment Form

On Other Sites

  • i5junkies: Thanks for this posting. It helped me fix the problem and running. GREAT post!!! [...]
  • emeka: i accidentally unscred all the screws and flipped my laptop now i dont know which screw goes where p [...]
  • Erik: Hey Matt! I came across your blog after seeing you had posted a link to our older website. I know t [...]
  • mot: haha - thats all i could say... thanks [...]
  • Motorola Phones - The RadioReference.com Forums: [...] Have a look at this page: Direct Talk Compatible Phones | Matt's Blog [...] [...]