Hibernate in Fedora

I spent time yesterday making HybridSleep and Hibernate work in Fedora 32 on a ThinkPad X1 Carbon with an encrypted disk.

I don’t ever plan to manually use hybrid sleep or hibernate; I’d instead just lock my screen or close the laptop lid. So why even bother to have them work?

It’s because hybrid sleep and hibernate are useful to have when battery power runs out. You’ll find in /etc/UPower/UPower.conf that the computer attempts hybrid sleep, hibernate, and a full shutdown, in this order, when the battery runs out. If you don’t want a full shutdown and to lose working state when this happens, you should want a working hibernate or hybrid sleep.

$ cat /etc/UPower/UPower.conf | tail -n 3
# If HybridSleep isn't available, Hibernate will be used
# If Hibernate isn't available, PowerOff will be used

How to use this guide #

There are 5-6 issues that users typically have. Each of them is described below, along with steps to fix them. I recommend incrementally implementing fixes, then checking if hibernate works — as opposed to implementing all fixes, some of which may turn out to be unnecessary in your case.

Does it already just work? #

The first thing to do, before doing extra work, is to check whether hibernate already just works™ in your computer. If you’re one of the lucky ones, then:

$ cat /sys/power/state
freeze mem disk

should include the output “disk”. Next try:

$ systemctl hibernate

Fingers crossed, your screen goes blank and your computer turns off. Turn on your computer again, log in as usual, and if your open windows were preserved you’re good to go—hibernate worked! You should try the same with hybrid sleep.

$ systemctl hybrid-sleep

On the other hand, if your /sys/power/state doesn’t include “disk”, and/or you see a failure message:

Sleep verb "hibernate" not supported

let’s dig in further.

SecureBoot #

One of the most common reasons for the inability to hibernate, and this is most likely true for Windows 8/10 laptops, is that SecureBoot is enabled. Disable SecureBoot in your BIOS; for my laptop this involves:

As for whether you should disable SecureBoot, I recommend doing some research since SecureBoot provides security benefits you might value over the ability to hibernate.

Once you’ve disabled SecureBoot, try systemctl hibernate again.

Do you have swap? #

On to more gritty details. Check if you have swap enabled, which is necessary to save your working state to disk during hibernation.

$ swapon --show
/dev/dm-2 partition 7.7G   0B   -2

If you don’t have swap enabled, follow a good online resource to add a swap partition (here’s a terse but accurate guide).

GRUB options #

Next up, GRUB has to know to that it can resume from your swap partition.

$ cat /etc/default/grub

Inspect the contents of GRUB_CMDLINE_LINUX (formatting modified for readability).

GRUB_CMDLINE_LINUX="resume=/dev/mapper/fedora_localhost--live-swap rd.lvm.lv=fedora_localhost-live/root 
rd.luks.uuid=luks-0962d4ff-5b38-4a4e-99e3-30509326c9b1 rd.lvm.lv=fedora_localhost-live/swap 

The important parts are that you require having listed are resume= and rd.lvm.lv= for swap. The actual values might be different for you. If either of resume= or rd.lvm.lv= for swap is missing, you should add it. But first you need to determine the two values to use.

For resume= the value can be found by running the following. Here the value would be /dev/mapper/fedora_localhost--live-swap.

$ systemctl list-units | grep swap

dev-mapper-fedora_localhost\x2d\x2dlive\x2dswap.swap  loaded active active  /dev/mapper/fedora_localhost--live-swap

swap.target  loaded active active  Swap

For rd.lvm.lv= the value can be found by running the following. Here the value would be fedora_localhost-live/swap.

$ sudo lvscan 
  ACTIVE  '/dev/fedora_localhost-live/swap' [7.72 GiB] inherit
  ACTIVE  '/dev/fedora_localhost-live/home' [<102.84 GiB] inherit
  ACTIVE  '/dev/fedora_localhost-live/root' [<69.99 GiB] inherit

After you’ve updated GRUB_CMDLINE_LINUX in /etc/default/grub, you must generate your grub.cfg to reflect the update. Assuming you’re using a UEFI computer (which most modern computers are) run:

$ grub2-mkconfig -o /etc/grub2-efi.cfg

dracut #

Finally, dracut and the boot image. Start by running:

$ sudo dracut --print-cmdline

The output (formatted for readability), if set up for hibernate, should include resume=.

rootfstype=ext4 rootflags=rw,relatime,seclabel

If it doesn’t, you need to add “resume” to the list of dracut modules. Create /etc/dracut.conf.d/resume.conf with the content:

add_dracutmodules+=" resume "

See the man page for dracut.conf if you’re interested to learn more.

Then regenerate the boot disk image:

sudo dracut -fv

and check that resume= is now listed in the earlier command output.

With all this done you should be ready to try systemctl hibernate again, which, fingers crossed, now works.

Resources #




Now read this

Vim-like cursor keys on a 60% keyboard

I’m using a 60% keyboard, which has 61 keys—the WASD VP3. It doesn’t have dedicated cursor keys, so I set up Fn + hjkl to act as cursor keys. The default mappings use Fn + ijkl as cursor keys. Fn + i: up Fn + k: down Fn + j: left Fn + l:... Continue →