hacky root partition resizing

Posted on Wednesday, 11 July 2007

How would you shrink the root file system of a remote machine? Of course the easy answer is to boot into a rescue environment and do it (because you can't shrink ext3 online).
If you have a good KVM or ILO setup, you already have a rescue environment of sorts - initramfs.
Chuck "break=mount" on your kernel commandline and the initramfs will drop out to a shell before it mounts the root filesystem. You can now mount the root fs manually and copy out the required tools/libs (e2fsck, resize2fs, fdisk and their libraries, in this case), then unmount the root fs.
Now, with appropriate $LD_LIBRARY_PATH mangling you can run the extracted binaries and operate on your root partition with impunity


  1. For what it's worth, to do such a root fs shrinking, you should first run e2fsck -f /dev/partition. Then do resize2fs -p /dev/partition XG. Then fdisk /dev/disk, delete the partition and make a new one with the same size (or slightly larger if you're not feeling daring) as the filesystem you shrunk.