Update for 16.04 (September, 2016)
Hibernate might not work not even it is successfully enabled if you have btrfs
partitions. As revealed in a question here
It was also revealed that enabling UEFI can cause problem with hibernation too.
Enable the Hibernate option
To enable Hibernate, I followed this answer from Dima.
After enabling hibernate you will have an option to hibernate in the indicator session menu at top panel. But, though you can hibernate you may not resume from hibernate. You will just be given a new session. The fixes are below.
The fixes to be able to resume from hibernate (12.04)
Several readers confirmed this working on 14.04 too
There is two way to fix this.
1. Editing the /etc/initramfs-tools/conf.d/resume
file
First get the UUID of the swap partition.
sudo blkid | grep swap
This will output a line similar to this:
/dev/sda12: UUID="a14f3380-810e-49a7-b42e-72169e66c432" TYPE="swap"
The actually line will not match with this. Copy the value of UUID in between "..."
double quote.
Open the resume file
gksudo gedit /etc/initramfs-tools/conf.d/resume
And in that file, add a line like this
RESUME=UUID=a14f3380-810e-49a7-b42e-72169e66c432
Don't forget to replace the actual UUID value you get from step 1. Save the file and exit gedit
Then in terminal, execute this command
sudo update-initramfs -u
You will now be able to resume from hibernation
2. Editing the /etc/default/grub
file.
Open a terminal and execute the below command to open it
gksudo gedit /etc/default/grub
There will be a line like GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
. Edit the line to insert RESUME=UUID=<your-uuid-value-here>
after the word splash
.
For example in my case, the line looks like this after editing
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=a14f3380-810e-49a7-b42e-72169e66c432"
Make sure, you used your UUID value you get from sudo blkid | grep swap
command.
Then do this command
sudo update-grub
This also enable you to successfully get resumed from hibernate.
Tested on two Ubuntu installation, both worked
I had the same issues. There is a bug in the most recent kernel in 16.04. Here are the explicit steps I have done. Do the first one and, if it solves the problem for you, stop there. If not, go on.
1. Set the computer to boot with the previous kernel
Start with:
uname -r
Mine says 4.13... Then do:
grep -i "menuentry '" /boot/grub/grub.cfg
You will see the different menu entries in grub. In my case, together with "Ubuntu, with Linux 4.13..." there was a menu option to boot with the previous kernel. It said Ubuntu, with Linux 4.10.0-28-generic. In the same line you have something like 'gnulinux-4.10.0-28-generic-advanced...(a bunch of caracters here)' Copy that text, and then we have to tell grub2 to boot with that kernel by default:
sudo cp /etc/default/grub /etc/default/grub.back
sudo gedit /etc/default/grub
Then I inserted this line:
GRUB_DEFAULT="gnulinux-advanced-4a50e1e8-56d9-413e-9954-55648888a31d>gnulinux-4.10.0-28-generic-advanced-4a50e1e8-56d9-413e-9954-55648888a31d"
Please do not copy this line literally, but use the output of the previous grep command as said. Then save and,
sudo update-grub
Then re-boot and check that the output of "uname -r" is the older kernel (4.10... in my case). You may be able to hibernate now, or not. If not, proceed to the next step.
2. Install different stuff to hibernate than the default one:
In my case, using the older kernel got rid of the black screen of death and allowed me to resume after hibernation, but the contents of the disk image were going wiped out, i.e. it was identical to a reboot, not hibernation. So I installed some shit that hibernates differently:
sudo apt-get install uswsusp
Then close the terminal, open it again and type:
sudo s2disk
This is supposed to hibernate the computer. If, after resuming, everything is as you left it, then you have solved the issue. But you still need to proceed to step 4 in order to tell Ubuntu that you want to use the new stuff by default and also that you want to have options to hibernate in the applications.
3. Tell grub 2 where the swap partition is:
It still didn't worked for me, so I had to tell grub where the swap partition is:
cat /etc/fstab
I could read there "# swap was on /dev/sda2 during installation", so I edited grub again:
sudo gedit /etc/default/grub
And added:
GRUB_CMDLINE_LINUX_DEFAULT="intel_pstate=disable resume=/dev/sda2"
The important part is "resume=/dev/sda2" but the previous thing (intel blablabla) is there because of other reasons. Well, the next step is:
sudo update-grub
Re-boot and try again to hibernate with some stuff going on (e.g. open a movie with vlc) with:
sudo s2disk
If the stuff is still there after you resume, you have solved the issue.
4. Telling Ubuntu to use the new hibernation stuff you have installed instead of the default:
You have now to tell Ubuntu to use s2disk to hibernate instead of the stuff that comes by default:
sudo gedit /etc/pm/config.d/00sleep_module
And insert there:
SLEEP_MODULE="uswsusp"
Save and close the file. Then:
sudo gedit /etc/polkit-1/localauthority/50-local.d/enable-hibernate.pkla
And insert there:
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
Reboot and try again.
5. If after running Step 4, you can't hibernate using sudo systemctl hibernate
then do the following
Step 4 is not enough to make the switch to uswsusp in Ubuntu 18.10.
Edit the hibernation service
sudo systemctl edit systemd-hibernate.service
And add the following
[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleep
Update systemd
sudo systemctl daemon-reload
Test the setup by running the following
sudo systemctl hibernate
Best Answer
There are changes done to default settings when compared to previous LTS (16.04). In my case hibernation didn't work until I've did several steps, among them increased the size of swap file, turned it on, made sure policies allowed it, etc.
This may easily be my lengthiest answer on entire StackExchange so I tried to make headers descriptive.
Boots as there was no hibernation
Would be prudent to take a look at your logs (
dmesg
might help) and see if anything's there. There are reasons when despite you telling the system to hibernate, it actually won't, or it will suspend-to-RAM instead (sleep).Taking a look at
kern.log
andsyslog
looking for any hibernate-related messages wouldn't hurt as well. Sections starting with "problem" may help you with specific issues.Swap file or swap partition
One of crucial changes is that now you DO NOT HAVE a swap partition, but you have a swap FILE.
Swap file may not work for your blend of hardware/drivers/OS and hibernation.
Hibernation turned off
Policies may also turn off or disallow hibernation.
Jargon
Suspend to RAM - RAM keeps the data, computer goes to sleep faster, uses more energy when suspended, wakes up faster. Some call this sleep.
Suspend to disk - aka hibernation. RAM is saved to swap (partition or file), computer goes to sleep slower, uses less energy while hibernating, wakes up slower.
Prerequisites - do you have enough space?
To hibernate, you need to (simplification here) save your entire RAM to your hard drive. So, you need to set aside enough space to do so. If you don't, this will fail and you won't hibernate.
free -m
will tell you how much memory you have, use and how much is in your swap.df -h
will tell you how much disk space you have on each mount point and how much is used, free, etc. This is important since you may want to later specify where your swap file will be located, or which partition to "trim" to have enough space for your swap.cat fstab
should give you information if you have a swap partition or file. According to Ubuntu Hibernation FAQswapfile
may not always work with some combinations of hardware/drivers.If you don't have enough space, follow Ubuntu swap FAQ. It tells you how to increase swap file, add another, check if it's used etc. With commands and explanations. Really nice resource.
I don't have enough space to fit my RAM!
Kernel docs say:
So, try tweaking your image size. How - ask another question please.
Prerequisites - does your kernel support suspend-to-disk?
Kernel supports whatever is listed in
/sys/power/state
, so:cat /sys/power/state
Allowed (to my knowledge) entries there include:
mem
,standby
,freeze
,disk
. Explanation:mem
- has several meanings, which one exactly on your system you'll find out viacat /sys/power/mem_sleep
. I have:s2idle [deep]
standby
- Power-On Suspend (if supported)freeze
- Suspend To Idle (STI)disk
- Suspend To Disk (STD), hibernation. This - you want.Then we need to check
cat /sys/power/disk
. If you have theredisabled
then dive in your BIOS looking for Secure Boot - that's the only idea I can offer and only thing I know may interfere and turn off hibernation. While I know only of SecureBoot, there may be other interferences, so taking a look at your BIOS is a good idea even if you don't have there any "secure boot".Reading here:
TBH, even if your kernel does NOT support hibernation, you can try it in another way, scroll down to section
Interfaces
.Read this - warnings and problems - no BTRFS
In no particular order:
Don't use BTRFS and hibernate: corrupted data will be the result.
I want to hibernate - swap partition
There are cases, when people forego swap file and go back to swap partition. After all, it worked on previous LTS. I did not try, so won't offer pointers.
I want to hibernate - with swap file
/etc/fstab
to new one. Reboot to see change is taken well (store backup of thefstab
so you can easily revert just in case.Kernel parameters? Scary!
Carefully read and decide if you wish to do that, but it's just a way to configure your kernel. It may be easier to hibernate via
systemd
anduswsusp
(see Interfaces, below). It may be, that you - like me - will ultimately decide suspend-to-RAM is enough and you don't want to have 32GB on a swap file (not so great for folks with one SSD in their laptops, for instance). But!resume=
to know which partition your swap file is on andresume_offset=
to know where in swap file to start resuming from.resume=
to point to swap partition.resumedelay=
.Kernel docs on delaying resuming from Hibernation:
Required parameters for swap-file and hibernation:
For the
resume=
choose the same style asroot
element has infstab
. So, either/dev/sdaX
orUUID
or LVM. For hibernating to file - provide partition where your file can be found.Reading:
Problem - swap header not found
Swap file needs to be formatted properly. If your logs tell you this, you either are trying to hibernate to a file, or your resume parameter is not right.
Switch to partition or fix the file or change interface used for hibernation.
See: https://unix.stackexchange.com/questions/43508/debian-hibernate-problem-pm-swap-header-not-found
mkswap
is used to format file, read more on it hereProblem! Hibernation not allowed!
Test:
pm-hibernate
(if pm-utils package is installed) orsystemctl hibernate
tell you you are not allowed. Default setting in Ubuntu since IIRC 12.04.Solution(s): depends on your Polkit version, your Ubuntu version and flavour... See this question. Also, ArchWiki on Polkit may help.
For Mint, see: https://forums.linuxmint.com/viewtopic.php?t=259912
Problem! Hibernation disabled by something in BIOS!
Test:
cat /sys/power/disk
hasdisabled
. Logs show "Failed to hibernate system via logind: Sleep verb not supported".Solution: search your BIOS and find the problematic thing. Turn it off.
Solution 2: try another hibernate interface.
See: How to activate hibernation in 16.04.1 ? (systemd).
Interfaces
Closing remarks
For me it was a matter of almost two days of work to compile that. Hopefully this will help you (and others) solve your issue faster. There are still points I missed but it's 2 AM and I don't feel like writing more now. I'm of course open to anybody's pointers to make this better, so comment away. I'll reply once I sleep, work etc. :-)
I'm not certain hibernating to disk is that great. I went with sleeping in the end. But for me issue was with having a 32GB file just to be able to do hibernation, since I'm usually avoiding swapping at all. My initial swap-file was at 2GB and it was mostly empty. YMMV. Nevertheless, good luck! And start with the logs!