East of the Sun, West of the Moon


Small, smaller, smallest

Filed under: Software — Erwin @ 12:58 pm

I have an old laptop, a Sony VAIO. Someone put (Debian) Linux on it before I got it, at my request, but the person that did this forgot (or never considered) to include a hibernation partition so the only option is to do battery powered suspend, which slowly drains the batteries until they run out, of course.

The harddisk had been partitioned such that there is one swap-partition (of 128MB, this is an old laptop, it doesn’t have much RAM of its own anyway, so no point in having a huge swap-partition) and one ext2 partition that fills the rest of the disk. Hrm. So no room left to add a hibernation partition!

Looking around for an appropriate partition-resize utility, I find GNU Parted which in theory should allow me to resize ext2/ext3 partitions, move them, etc. There’s one catch, however: It does not allow you to work on a partition that’s currently in use, even if it’s mounted readonly. Given that I only have the one partition, that appears to create a bootstrap problem:

Need Parted to resize the existing partition and make room for another one, yet need to have a partition other than the one existing one to be able to run Parted!


There is still that swap-partition (a.k.a virtual memory for those not quite fluent with the terminology). While useful, strictly speaking Linux can certainly run without it, it just means it has no place to dump toxic memory waste, so to speak.

So I do the following:

  • Disable the swap-partition and remove it from the configuration so it won’t be used again accidentally.
  • Create a brand new ext3 filesystem on it, instead.
  • Copy relevant directories like /boot, /dev, /etc, /bin, etc.
  • Create a new /etc/lilo.conf entry that will use this as the root-filesystem.
  • Boot in single-user mode using this entry, and run Parted as intended.

I still had to fix /etc/fstab which pointed to the wrong root-filesystem and /etc/mtab which thought various (pseudo-)filesystems were still mounted, but then it actually worked, the main partition is now one GB smaller than before.

Next step is to download and install lphdisk. I downloaded the sources and tried to compile, but they must use a slightly different compiler than GCC 3.3, as a string-continuation in one place didn’t succeed and I had to edit the C source code. Oh well, glad I still know how to read and adapt in that language.

A bit of trial and error with fdisk and I manage to set up a partition at the end of the (logical) harddisk that should be big enough for the purpose, then give it the appropriate flag (A0 == IBM Thinkpad hibernation). First a test-run, then the real thing:

# ./lphdisk /dev/hda
Reccomended partition size is 132 MB (270210 sectors)
Creating hibernate area on /dev/hda, partition 4…
Formatting sector 272160 of 272160. (sectors of 512 bytes)
Format complete.

[The typo in recommended is an original, not mine]

The change didn’t take immediately, I had to reboot one more time for the BIOS to realize the partition was there and intended to be used. Now tt’s working beautifully, however, with a certain feeling of nostalgia when the © 1997 shows up in that preparing for hibernation BIOS screen.

I’ll probably play some more with Parted now that I’ve seen it work successfully in practice, as I’d been wanting to create a 2nd partition on the disk with which to start a clean install, the current one is a bit crudded up, so to speak.

So when was the last time you used a harddisk partition that was this small? 🙂

Powered by WordPress