Disk Resizing Up and Down

I just released a new feature for resizing disk images both larger and smaller.

For resizing larger, the only change was that if you resize a disk image labeled as swap, it will delete and recreate the swap image. Previously it would resize the Image itself, but not re-make the swap within.

For resizing smaller, it will only work on ext2/ext3 and swap disk images. Other image types it will abort. Resizing ext2/ext3 is non-destructive — it will attempt to resize the filesystem within and abort out if there isn’t enough free space. Aborting leaves your disk image untouched, so it is safe to “try” different sizes if you’re really trying to get the disk image as small as possible. We’re using the “resize2fs”, part of the [url=http://e2fsprogs.sourceforge.net/]e2fsprogs[/url] package.

Here are some of the results of my testcases

Test Results[/size]

[b]Initial Image: RedHat 9.0 Small, 1500 MB[/b]

[code]Filesystem Size Used Avail Use% Mounted on
/dev/ubda 1.5G 875M 576M 61% /[/code]

[b]Resize from 1500 to 1000[/b]

After Resize:
[code]Filesystem Size Used Avail Use% Mounted on
/dev/ubda 987M 842M 135M 87% /[/code]

[b]Resize from 1000 to 900[/b]

After Resize
[code]Filesystem Size Used Avail Use% Mounted on
/dev/ubda 887M 842M 36M 96% /[/code]

[b] Resize from 900 to 800[/b]

Errored out with “No space left on device”. Remained 900 MB. File unmodified on host. Booted correctly, df reported:
[code]Filesystem Size Used Avail Use% Mounted on
/dev/ubda 887M 842M 36M 96% /[/code]

[b] Resize from 900 to 1500[/b]

After resize
[code]Filesystem Size Used Avail Use% Mounted on
/dev/ubda 1.5G 842M 624M 58% /[/code]

Notice the “Used” space is less after the first resize. I’m guessing we reclaim some space after running fsck.ext3, and perhaps starting a new journal.

Thanks, and Enjoy!

PS – I’d appreciate it if some of you want to test this on scratch disk images and report the outcome here.


Leave a Reply

Your email address will not be published. Required fields are marked *