>How does one shrink an ext2 partition?

One usually doesn't. Instead, copy the data off, resize the partition using fdisk, and re-run mke2fs to recreate the metadata. Then copy back you saved data.

Much simpler would be to just delete the swap partition, and recreate it again 2 blocks smaller, giving you 4K of available space to play with.

Or, I could hack the kernel for you to provide a means of locating the blocks of an ext2 file on disk, so that you could re-write a file "in-situ" on a readonly filesystem. No chance of any fscking screw ups that way. To locate the file, I'd just have an ioctl() stub that invokes ext2_getblk() on the inode, which will return the block address within the partition. This can then be used as an offset for doing a write() on the raw partition (/dev/hdx), bypassing the filesystem code.

Cheers