Yesterday I opened my laptop to find again that it had shut down due to low battery and I had lost my open windows. This happens when my laptop is booted into linux (almost always) and is "suspended" for too long off of AC power.

This has never been a big deal for me, because I don't tend to have unsaved work when I close my laptop, but it is an annoyance, and I finally committed to fixing it. I already had a "swap" partition—a section of my long term storage that serves as overflow space for when I have too many applications running. These swap partitions can also be used as a dumping space for all running memory. This is necessary to hibernate because random-access memory (RAM) is wiped when it doesn't have an electrical current.

So, I did a bit of browsing and found this helpful tutorial that went a bit beyond the usually excellent ArchLinux wiki in laying out the steps I needed to take. It so happens that I already had the necessary resume hook in my initial ramdisk configuration, so all I needed to do was tell the (GRUB) bootloader where to find the data it needs to resume, by specifying the swap partition's unique identifier.

The result is functional, but not exactly seemless. When I power on after hibernation, I still need to hit F12 at the BIOS screen to select Linux (instead of Windows, a default set by a recent firmware upgrade), enter my full-disk-encryption key, and then wait for that decryption and for GRUB to do its thing. But, at the end of the process, I end up with my ordinary lockscreen and my applications just as they were before. So, not something I will do regularly (suspend is much more convenient), but when I do go low battery, it might save me some hassle. And, it was satisfying to make a small improvement in my configuration.

Something I worry about is having to redo (and worse, relearn) these types of configurations in my next machine. I have a few tactics that can help with this challenge (aconfmgr, snapper, restic, org-roam, all of which I might post about at some point), but maybe sharing here will give me yet more breadcrumbs.