Linux – hibernate Linux without a swap partition

hibernatelinuxswap

I hadn't set up a swap partition on my PC, because a) I have plenty of RAM (8 GB) and b) I have large harddrives that I didn't want to chop into tiny pieces, so my smallest partitions are 50 GiB, and I'm already using those for the OS's.

Now, to hibernate, my Linux (Ubuntu Jaunty) required swap. I had a spare 100 GB partition so I set that up as swap, but I'm not satisfied with that. It's only ever used for hibernation (there's always plenty of RAM free and the system never goes to swap) and it's also a little large for swap. Also, I'm eventually going to need it for something else.

How can I hibernate (suspend to disk) without a swap partition in Ubuntu Jaunty?

Best Answer

Untested idea: why don't you create a wrapper for s2disk or whichever utility handles suspend to disk which manages a swap file ( as opposed to a swap partition ) and deletes it on resume?

  • Create the swap file : dd if=/dev/zero of=/swapfile bs=1024 count=8388608 ( 8GB )
  • Setup the swap file: mkswap /swapfile
  • Only when you need to set suspend you can activate it: swapon /swapfile
  • When you resume you can deactivate it: swapoff /swapfile

Resuming from swap files is possible, and is documented on kernel.org