Posts
- Hibernating to disk
- Django and manual data prefetch
- Django, window functions and paginator
- How I discovered MPV
- Pake - wrapping websites
- Accordion with animated height
- Nginx: HTTP and HTTPS on a single port
- NeoMutt: new Thunderbird
- How I solved the dilemma of personal notes
- Django model constraints
- Simple keyboard udev rule
- Kitchen LEDs and Home Assistant
- Home Assistant Nginx proxy server
- Rust and it's ability to insert/replace string into another string onto specific position
- Python HTML table parser without dependencies
- Python defaultdict with data
Hibernating to disk
Why?
I own TUXEDO InfinityBook Pro AMD Gen9 which had an issue with suspending to RAM. The laptop kept waking up, and I ran out of battery in about 12 hours while thinking the laptop was asleep.
I knew that there was something like "hibernating to disk" which basically saves current system state, dumps it to disk and powers off completely. So when you turn if back on, it restores to that state with 0% battery loss.
I finally got this working on my Debian Trixie, so I'm sharing how-to.
I'm pretty sure these steps will work on other laptops and distributions
as well, since it doesn't rely on any Debian-specific features. You may
just need to use your local equivalent of systemctl
, but that's only
one command.
How?
The computer hibernates to swap. It basically dumps memory into swap, so you need to have room to store that data. Many recommend having swap equal to or larger than your RAM. In my case, that would mean 64GB+, which seemed unnecessary. My laptop barely uses swap at all (because it has plenty of RAM), so that rule felt excessive.
Luckily enough that rule is not a requirement -it's just a safe threshold. If, for examle, you have 32GB or RAM actually in use when you hibernate, you'll need at least that much swap. Otherwise you don't.
I observed my RAM usage. Excluding virtual machines and temporary computations (you won't hibernate in the middle of heavy tasks anyway), I barely go above 16GB. So I decided to make my swap 16GB.
How to actually setup hibernating?
First, you need to know the ID of your swap partition. That can be done like this:
$ sudo blkid | grep swap
Copy the UUID=...
and add it to your GRUB kernel parameters under
resume
attribute like:
$ sudo vim /etc/default/grub
Find the line with GRUB_CMDLINE_LINUX_DEFAULT
and add this at the end:
resume=your-string-you-just-copied"
You'll end up with something like:
GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=UUID=................"
Now save the file and rebuild your GRUB config.
$ sudo update-grub
Try it out
Just do (no sudo needed):
$ systemctl hibernate
Your system will hibernate after a few seconds and save to disk. Next time you turn your computer on, your system will restore to the state you left it.