Enabling Hibernation on Linux Laptops
Due to issues with the latest sleep states in laptops I’ve had to resort using hibernation or S4 as the strata for all my Linux laptops:
- Lenovo X1 Carbon Gen 8 (intel 10th gen CPU)
- HP Gram 17z90n (intel )
- Dell XPS 9315 13 i5
My older laptops like the System 76 Darter Pro before they moved to CoreBoot systems and Dell XPS 9380 still functions quite well in S3 state, not requiring hibernation.
The benefits have been a massive improvement to battery life when left closed for up to a week or two. The down side is that you must login, or in my case unencrypt LUKS with a password every time you reopen the lid but with resume, it goes exactly back to where you were when you closed the lid.
Hibernation/Sleep Levels (S-States)
s0 (Working/On) - Normal operation.
s0ix (Modern Sleep) - Found on most modern laptops. Also functions with s2idle or Suspend-to-idle which offers low power mode with quick resume.
s1 (Sleep) - CPU stops, RAM stays powered on, but uses less power than s0.
s2 (Sleep) - CPU power off, RAM stays powered on. Deeper sleep than s1.
s3 (Suspend-to-RAM / Standby / Deep) - Mostly powered off, RAM stays powered on, fast resume, great battery life) My prefered but harder to find devices that support this after the Intel gen 10 series. Gen 11 onward usually only have sxi0.
s4 (Hibernate / Suspend-to-Disk) - All power offf, RAM content is saved to disk (swap), slowest resume which goes through the entire boot cycle, zero power use. The current way to get hibernation to work on Linux devices that do not support s3 anymore. Provides a very efficient hibernation that does not drain battery if at all but requires the system to completely boot up again. If you have LUKS encryption enabled at boot time you will be required to type in your password every time it wakes from s4. Not my ideal but functions remarkably well.
s5 (Off) - Full Shutdown.
new kid on the block
sxi0 - More efficient hibernation. Seems to only work with Windows and not so much if at all on Linux.
I just recently purchased a Dell 9315 XPS 13 in i5 10:16 laptop off of eBay after doing a ton of research to see if it was Linux worthy. Not only is it Linux worthy but I have been able to get it setup with one of the best features that most laptops are unable to do now due to Window’s push on the way they believe laptops should sleep/hibernate. On a WIndow’s system it runs well but outside of that world, battery life and suspend modes are not the best.
- Check what your system has available:
cat /sys/power/mem_sleep (shows s2idle, shallow, deep) - Set state but only until a reboot:
echo deep > /sys/power/state or ehco s2idle > /sys/power/state
Tips on how I got hibernation working permanently:
https://joshtronic.com/2018/10/12/hibernate-laptop-on-lid-close-with-systemd-boot-on-arch-linux/ and using Arch Linux’s Wiki: https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate
The first link got me about 75% of the way to where I needed to be but in their setup they use systemd-boot (AKA gummi-boot) process, where I’ll be sticking to regular ol’ GRUB2.
Prerequisites
- You must have a swap file. My easy-arch-ext4 github script creates a .swapfile at / where you get to determine the size you want. Its recommended to use 1.5 times the amount of available ram you have.
16GBof RAM means you will need24GBfor the swap file. This allows a buffer so that your RAM will not lose anything when going put in hibernation mode as it will right it to disk from the RAM. - In my case I use
LUKSfor my root directory so I will show that way to do it. - I also assume you use
mkinitcpioand notdracutas you will need to adjust to how dracut is used instead
Setting up the swap file if you do not have one already installed
- Create the /.swapfile
sudo dd if=/dev/zero of=/.swapfile bs=1M count=24576 status=progress
- Enable the swap file and setup permissions
sudo chmod 600 /.swapfile && sudo mkswap /.swapfile && sudo swapon /.swapfile
- Add to bottom of
/etc/fstab:
/.swapfile none swap default 0 0
- We next need to get the swap file offset which is needed for resume function:
sudo filefrag -v /.swapfile | sed -n '4p' | awk '{print $4+0}'
- Copy the output value as we will need to use this in our
/etc/default/grubfile:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<UUID-NUMBERS-OF-YOUR-ROOT-DEV-MAPPER> resume_offset=<offset>"
sudo blkid
/dev/nvme0n1p1: UUID="695B-E157" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="ESP" PARTUUID="a9774f1e-2ece-4fb8-a690-96b294a9178b"
/dev/nvme0n1p2: UUID="9b1cdb7a-1ec3-4670-8b8a-5a2be0c53b8f" TYPE="crypto_LUKS" PARTLABEL="CRYPTROOT" PARTUUID="d2a75464-1702-488a-9713-7b329fbdcdf6"
/dev/mapper/cryptroot: UUID="4eff707f-9a61-49b0-ba4f-269e858a9389" BLOCK_SIZE="4096" TYPE="ext4"

- Edit the
/etc/mkinitcpio.conffile and add resume to theHOOKS=afterudevwithout the**symbols:
HOOKS=( base udev autodetect modconf block encrypt filesystems keyboard **resume** fsck)
Run ‘sudo mkinitcpio -P` as this will update all the kernels you have with the latest mkinitcpio hooks.

- Enable hibernation on lid close in the
/etc/systemd/login.conffile:
HandleLidSwitch=hibernate
HandleLidSwitchExternalPower=hibernate
HandleLidSwitchDocked=hibernate
Run sudo systemctl enable systemd-logind and reboot to take it into effect.
Next time you close the lid the system will go into hibernation mode. Upon opening the lid and or having to also hit the power button, the laptop will boot through GRUB then LUKS will begin where you will then need to enter your password, which will bring you to the session you had before you closed your lid.