Resizing Xen Disk Images

My Xen host was only created with a 4GB partition:

bart:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 4.0G 2.8G 1.1G 73% /
tmpfs 129M 0 129M 0% /lib/init/rw
udev 10M 24K 10M 1% /dev

With hindsight, this was far too small.
If you a using basic ‘file’ based images you can safely resize them:

First of all make sure you create a backup of your current image:
(Make sure that the image is not mounted or running.)

bart:~# cp hd.img backup.img

bart:~# dd if=/dev/zero of=hd.img bs=1M conv=notrunc count=1 seek=8000

This will resize the image to approx 8GB.

Now boot your host and expand the filesystem:

bart:~# resize2fs /dev/sda1
resize2fs 1.40-WIP (14-Nov-2006)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/sda1 to 2048256 (4k) blocks.
The filesystem on /dev/sda1 is now 2048256 blocks long.

bart:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.7G 2.8G 4.6G 38% /
tmpfs 129M 0 129M 0% /lib/init/rw
udev 10M 24K 10M 1% /dev

😀

This entry was posted in Computing, Debian, Linux and tagged , , , . Bookmark the permalink.

Leave a Reply