Sun Nov 28 20:30:15 EET 2010

How to workaround (fix) hibernate "PM: Cannot find swap device, try swapon -a" GNOME issues on Debian testing/unstable Linux

I can't remember precisely but after one of the updates I did through apt-get update && apt-get upgrade or through aptitude update && aptitude upgrade. My gnome hibernate function has suddenly stopped working on my Thinkpad R61 notebook.
The exact kernel I currently run on my linux desktop is:

Linux noah 2.6.32-5-amd64 #1 SMP Sat Oct 30 14:18:21 UTC 2010 x86_64 GNU/Linux


My Debian linux version is:

hipo@noah:~/Desktop/blog-topics$ cat /etc/issue
Debian GNU/Linux squeeze/sid \n \l


This hibernation issue is pretty annoying since I'm so used to the hibernate that I practically use it instead of shutdown all the time.
I'm used to shutdown or restart my pc every couple of days or whenever the machine freezes up completely and a hard restart is necessary.
Therefore the hibernate is a crucial function for me to use on daily basis
That is the case especially when I use my computer at school, whether I had to move from a place to place and start and stop my thinkpad notebook quite regularly.

After one of the last updates as I said, whenever I tried to hibernate my computer it didn't worked out.
Everytime I pressed the fn + f12 to get the pc to hibernation I was unpleasently surprised by the message:

PM: Cannot find swap device, try swapon -a.

It took me a while until I found something that relates to the problem, but eventually I found out on the ubuntuforums some discussions about guys who has experienced the same shitty hibernation issue as me.
The exact forum thread which helped me on ubuntu forums can be red here

As it was described in the thread one probable reason for the issue was in the /etc/initramfs-tools/conf.d/resume file.

The solution from the forum suggested that in the /etc/initramfs-tools/conf.d/resume file contains a wrong UUID identifier of the swap partition to be found in fstab.

On a purpose some time ago during the updates of my Debian unstable distro I did removed completely the UUID identifier and prefered to use the good old and more readable way of directly placing the /dev/sda / /dev/hda etc. partitions.
That is why my /etc/fstab's UUID prefixes to my partitions were completely commented in my /etc/fstab

Anyways as I suspected something could be wrong with the /etc/initramfs-toold/conf.d/resume I checked the file and realized actually some of the updates has messed it up wrongly including an RESUME= file value to be

#RESUME='UUID=8e0901b1-d569-45b2-902d-e159b104e330'

As I didn't used the UUID at all it should have contained:

RESUME=/dev/sda7
In my case it should have been sda7 because sda7 is my swap partition, however on other machine this could vary.

Changing this and testing my machine hibernation in GNOME produced the same error;

The ubuntu forum thread helped me to understand that actually using the hibernate in Gnome does execute the /usr/sbin/pm-hibernate shell script.

Furthermore I tried modifying this script to fix the shitty PM: Cannot find swap device, try swapon -a. but I had zero success in this ...

As I already new my /usr/sbin/hibernate shell script as invoked from my console was properly hibernating my notebook and instead of simply using the menu;

System -> Shut Down -> Hibernate


Or via simply pressing the Fn + F12 hibernate shortcut I had everytime to switch to text console and from there, after logging in with the root account to issue the command;

noah:~# /usr/sbin/hibernate


This kind of complicating the simple task of hibernate was quite not user friendly, after some more desperate attempts to modify and fix up the pm-hibernate in order to make the script to detect my already mounted swap partition I finally give it up with the script.

Another thing that I thought might be necessary to get rid of the message after edidting the /etc/init-ramfs-tools/resume script and setting the RESUME variable inside it to the proper one was:

noah:~# /usr/sbin/update-initramfs


This worked nor, so I was quite angry but still hoping that somehow I'll be able to come up with some kind of work around to the hibernate issue.

Alas thanks God after a bit of thinking over the problem I was able to come with a very simple workaround I thought; "Well if the pm-hibernate is novoked via hibernate in Gnome and it's not working but the /usr/sbin/hibernate is working, then I'll just make the pm-hibernate to execute the /usr/sbin/hibernate instead of the /usr/sbin/pm-hibernate.

Guess what it worked like a charm :)

All I had to do to get rid of the very annoying error:

PM: Cannot find swap device, try swapon -a.

came up to issuing the following two simple lines in my gnome-terminal;

debian:~# mv /usr/sbin/pm-hibernate /usr/sbin/pm-hibernate.old
debian:~# ln -sf /usr/sbin/hibernate /usr/sbin/pm-hibernate


I know this kind of workaround to the hibernation Debian issue could be just temporary and probably after the next update of my hibernate Debian testing/unstable package it will stop working again, however it works at least for now .

Now my GNOME hibernate functions works again on my Debian powered Thinkpad and I'm happily hibernating it all the time again.
I hope this post will help up to somebody experiencing the same issues on his Debian, Ubuntu or any other Debian based distribution!