enable hibernate while having swap disabled

Did you ever wonder how to be able to hibernate you Linux OS without enabling swap?

Imagine, you have a SSD and enough RAM installed – why would you allow your OS to write to your SSD for swapping? But on the other hand, you need a swap partition to be able to hibernate your system.

The trivial idea is to enable/disable the swap partition right before/after the hibernation takes place. Here is how you achieve this behavior:

  1. Place this script in the directory /etc/pm/sleep.d with a meaningful name, e.g. 80swap and make it executable.
  2. To avoid that the swap partition gets enabled upon boot, add the noauto option to the entry of your swap partition in /etc/fstab, example:
/dev/sda2   swap    swap    defaults,discard,noauto 0 0
  1. To allow uswsusp to be reconfigured from apt/aptitude the swap partition must be mounted during installations (otherwise, you cannot resume after a kernel upgrade). Place this apt configuration into /etc/apt/apt.conf.d and you are done.