How should I successfully hibernate Ubuntu 16.04?
I've tried almost every solution on the web but non of them was actually helpful. I found my problem almost completely similar to this one
systemctl and getting it working in tough cases
pm-hibernate always fails. After some tweaks, I was able to hibernate using the interface of systemd (init system in 16.04 and above). I also managed to get it working on 17.04 with a swap file. This case study might be useful for people with problems
sudo systemctl hibernate
If that fails, begin troubleshooting: in the hibernate state (htd or acpi s4) the machine state is written to disk so that no power is needed to preserve it. The state is written to either a swap partition or a swap file Note: if using Btrfs DO NOT attempt to use a swap file as this may cause filesystem corruption
Your swap partition or swap file may need to be the same size as RAM to allow hibernation, but there is a good chance you will be able to hibernate if it is at least 2/5 the size of RAM, according to the Arch wiki page , so try other steps first before increasing swap size.
If your problem is that you get a clean boot instead of the expected resume, at a minimum you most likely need to set a boot parameter to find the disk image
Find the swap partition
grep swap /etc/fstab
for me this returns (partial output)
# swap was on /dev/mmcblk0p3 during installation
/dev/mmcblk0p3 is the partition to specify
Add a parameter boot
To the line starting
resume=/dev/YourSwapPartition to the section in quotes (replace with the the partition you identified earlier). Using my example.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=/dev/mmcblk0p3"
Any time you change this file, you must run
sudo update-grub or the changes will have no effect.
You need to reboot now You can then try to hibernate by issuing the command
sudo systemctl hibernate
When the system is started press the power button again and the system will boot
If you still have problems, start debugging.
Set some more boot parameters to gather more information Remove
splash and add
no_console_suspend which will cause init system calls to be printed to the console so you can watch what is going wrong. I've done it
GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/mmcblk0p3 no_console_suspend initcall_debug"
Which helped me to see what was wrong with my resume from hibernation You can also try using
In my case, after resume I lost WiFi, and the kernel clearly was upset as most commands (for example reading anything from
/sys , reloading modules or any
systemctl command) would not work - the process would appear to start and just hang (all this would be returned to normal after reboot of course). Watching the system very slowly shut down and reading all the debug messages, i noticed that there were a lot of problems with "brcm", so i guessed my broadcom wireless driver module was to blame. I figured out my hibernation procedure by first unloading the module
sudo modprobe -r brcmfmac sudo systemctl hibernate
on resume I reinsert the module
sudo modprobe brcmfmac
Everything worked perfectly I also have to blacklist the
btsdio module which seems to be incompatible with
Update: Hibernation using a swap file on 17.04.
Once again with help from the Arch wiki page and some additional tinkering, I managed to get hibernation to work on 17.04 with a swap file. This required an additional boot parameter,
resume_offset=n where n is the first number under
physical_offset in the output of
sudo filefrag -v /swapfile .
$ sudo filefrag -v /swapfile Filesystem type is: ef53 File size of /swapfile is 1425873920 (348114 blocks of 4096 bytes) ext: logical_offset: physical_offset: length: expected: flags: 0: 0.. 32767: 34816.. 67583: 32768: 1: 32768.. 63487: 67584.. 98303: 30720: ....
Therefore, the additional boot parameter in my case is
resume_offset=34816 . You still need to set a boot parameter for the partition to start from This is the root partition or whatever partition your swap file is located on
GRUB_CMDLINE_LINUX_DEFAULT="no_console_suspend initcall_debug resume=/dev/mmcblk1p2 resume_offset=34816"
/dev/mmcblk1p2 is my root partition (yours is more likely to be something like
During resume I saw the image loading successfully, but in my case (just an example - YMMVAPD) then some more drivers (
i2c_designware ) threw some errors and I got a complete system freeze on resume. Hibernation works if I unload those modules in addition to
brcmfmac , but the system quickly becomes unusable without those modules. So i wrote a script to unload the grumpy modules and immediately reinstate them when i resume
# remove buggy modules modprobe -r brcmfmac i2c_designware_platform i2c_designware_core && # hibernate echo disk > /sys/power/state # reinsert modprobe i2c_designware_core i2c_designware_platform brcmfmac
When I want to hibernate, I run
sudo bash script . This works very well
Use systemd, set a boot parameter for resume from swap, identify buggy drivers and unload them before initiating hibernation. If the system doesn't work long without those modules or you need to unload several it may be easier to use a simple script to initiate hibernation