Home » Questions » Computers [ Ask a new question ]

Can I hibernate Linux without a swap partition?

Can I hibernate Linux without a swap partition?

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.

Asked by: Guest | Views: 237
Total answers/comments: 2
Guest [Entry]

"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 kerneldotorg"
Guest [Entry]

"Yes, but not without some effort. There are 2 different ways to hibernate (suspend-to-disk) on linux:

swswap, which is included in the kernel
tuxonice (formerly suspend2), which is not.

Tuxonice is available as a patch to the kernel, and will let you write the suspend image to an ordinary file.

From Wikipedia:

TuxOnIce (formerly known as Suspend2) is an implementation of the suspend-to-disk (or hibernate) feature which is available as patches for the 2.6 Linux kernel. It was formerly known as 'swsusp'. During the 2.5 kernel era, Pavel Machek forked the original out-of-tree version of swsusp (then at approximately beta 10) and got it merged into the vanilla kernel, while development continued in the swsusp/Suspend2/TuxOnIce line. TuxOnIce includes support for SMP, highmem and preemption. Its major advantages over swsusp are:

* It has an extensible architecture that allows for arbitrary transformations on the image and arbitrary backends for writing the image;
* It prepares the image and allocates storage prior to doing any storage and accounts for memory and storage usage very carefully, thereby becoming more reliable;
* Its current modules for writing the image have been designed for speed, combining asynchronous I/O, multithreading and readahead with LZF compression in its default configuration to read and write the image as fast as hardware is able;
* It has an active community supporting it via a wiki, mailing lists and irc channel (see the TuxOnIce website);
* It is more flexible and configurable (via a /sys/power/tuxonice interface);
* Whereas the current swsusp (and uswsusp) implementations support writing the image to one swap device only, TuxOnIce supports multiple devices in any combination of swap files and swap partitions. It can also write the image to an ordinary file, thereby avoiding potential race issues in freeing memory when preparing to suspend.
* It supports encryption by various methods;
* It can store a full image of memory (resulting in a more responsive system post-resume), while uswsusp and swsusp write at most half the amount of RAM.

Since it's not included in the default kernel, you'd unfortunately have to pick up the kernel patches available for Jaunty and compile the kernel yourself.

There are some extended instructions here, but you might want to try out Robert's suggestion before wandering down this road, unless you are an old hand at rolling your own kernel images."