Hibernation? Using it?

So I have wondered for a while now, why, exactly, Linux as a whole abandoned hibernation. I read that it didn’t work right on some hardware configurations and luks was difficult, etc, and so for these reasons they just figured not enabling it would save a lot of heartburn for people.

BUT, hibernation is the perfect answer for most standby power drain issues. With the speed of NVME drives, it really is a no brainer.

I prefer to use standard standby when I know I’ll be using the computer again within a few hours (1-10 hours). If I don’t know when I’ll use it next, I can always just hibernate.

Why is hibernation so useful? You can shutdown the computer completely, and when you resume you are right back where you were. Your session is preserved, just like with standby. It’s a no brainer.

All this said, who is using hibernation?

I plan on setting it up on Ubuntu 21.04 after work today.

Edit: was able to setup it up using a partition on a module drive (250gb). I have 64gb RAM and the partition is 70GB. It hibernates in about 9 seconds, and resumes in about 7 seconds. Very happy with that.

8 Likes

I would but I usually just shut down, for the same reasons. Boots in seconds, why worry.

I don’t like leaving my computer on, old habits from Atari 800 days.

7 Likes

Hibernation on linux does not write to arbitrary disk/partition, it writes to swap, so your swap partition must be atleast the size of ram or more. As higher amount of RAM is coming on and on like 32G/+ and also distros like Garuda who says unused RAM is wasted RAM, will genunely have problem in managing these. You can always enable hibernation, most of init systems support it, if it doesn’t acpid supports it, if you donot want to use acpid void linux for example provides a zzz utility zzz(8) - Void Linux manpages, you can install in almost any system as its systemd-free.

Its really not abundant but rarely used, due to some risks over data corruption etc if you boot into another linux and that uses the same swap partition. There are many other reasons too but mainly this. Suspend to RAM aka sleep is more prominent and is very effective as well. CPU and monitor sleeps which is most power consuming component of the laptop.

Also if you use runit init system I’d guess you can probably cold boot in about 6-10seconds in the cpu provided, and move on to your work without any lags.

1 Like

Do you factor in the time needed to get back into your workflow? Opening applications, clicking menus, etc.?

With hibernation, you can hibernate, leave the computer for 10 days, come back, your battery is where it was, and your session is right there ready to go again.

In general I would agree with you, but I think hibernation should be looked at as a better version of shutdown.

1 Like

My habits from years ago always involved closing applications before shutdown.
Hibernation and sleep were not an option.

I am also rarely wanting to restart exactly where I left off.

Good thing we have choices, isn’t it?

4 Likes

Oh absolutely!!! Wouldn’t want it any other way. I suppose my love for choices is why I’m questioning the removal of hibernation by default on Linux distros.

3 Likes

Agree, it annoys me how much has been removed from cell phones.

Replaceable batteries
Headset Jack’s
Extra ram slots
And other neat things
Blood pressure
Blood oxygen
And who knows what else people found useful.

3 Likes

In general I’m quite disappointed with macOS, every time I’ve had to use it for work; but one thing macOS does well is transparently mixing sleep and hibernation. It automatically decides, using logic I’m not really sure about, whether to hibernate immediately, or to wait a bit and turn a sleep into a hibernate; and both look the same to the user except waking from a hibernate is slower.

I think most of this would work on generic PC hardware just fine.

Maybe with large memory sizes though, it’d be nice to have some sort of incremental resume from hibernate, where you start paging in the memory from the swap piecemeal to get it running while you wait for the whole memory to restore.

2 Likes

Note that your swap partition or file does not necessarily need to be the size of or bigger than your memory. First, a lot of kernels are configured to (very effectively in my experience) compress data during hibernate, so you will never need more than total memory size. Second, there is also a lot of data in memory that is not needed to be saved for hibernation, e.g. cache. On Arch, for example, hibernation is set to target using up to 2/5 of total memory. While it can use more, how often are you hibernating with 90% of your memory in use?

I’ve never had an issue hibernating with a 16GB swap with 64GB of memory, even works when I am using over 16GB.
At the end of the day, it doesn’t really matter that much, as disk space is pretty cheap nowadays, but I just wanted to put this out there :stuck_out_tongue:

4 Likes

Thanks shark! When I was getting hibernation working on Ubuntu 18.04 a while ago, if the swap partition was not the same size as the installed memory, at least, it would error out saying that the swap wasn’t big enough for hibernation operations.

It would be excellent if they were using a form of compression or filtering out information not necessary to replicate in order to make the target size not as large.

You know, I hadn’t looked at hibernation on Linux on a long time due to many issues with it in the past, but you twigged me to give it a shot again, and lo and behold, it… just works?

I’m honestly a little surprised!

And it works around an issue where, if I suspended my laptop while plugged into my USB dock, then unplugged, it would fail to wake up (and vice versa). With hibernation it works fine.

A couple tips for folks who want to try this:

  1. Make sure you have a swap space (either a partition or a file) at least as large as your physical memory.
  2. Update /etc/default/grub and to the kernel arguments add “resume=UUID=[uuid of swap space]”. You can get the UUID from blkid.

Then you can test with “systemctl hibernate”.

If you’re happy with it, you can integrate hibernate into your system with some tips from here:

and here:

6 Likes

I have hibernation working!

My Void Linux setup script configures it for me, and I can hibernate with zzz(8) - Void Linux manpages without issues.

The important details are:

  • 2x Swap over RAM (the norm is either no swap or 2 gigs or so of swap)
  • A comment in your grub config for where restoration information can be found.
3 Likes

I think hibernation is a great and am thinking about setting it up on my framework when I get it, planning on using ubuntu 21.04. The only concern I have is the extra writing to the drive causing the drive to fail ealier than it normally would. Please let me know if the effect would be negligble on the drive.

Honestly, the average SSD has so many spare cells for wear leveling, I’d be a lot more concerned with spinning drives wearing out these days.

Besides improvements in the tech behind SSDs I would also consider that you aren’t, or at least I’m not, hibernating every single time you use the computer. Something you’ll just use standby.

In my case, my hibernation partition is on a 250gb ssd module. As it is not using the full size of the drive, I imagine I will not see the thing wear out before the controller on the module dies. Which is to say, not for a long time. I’m not really concerned about it. If it does wear out, I’ve got the perfect laptop for that situation. :+1:

I am waffling about whether I want to try to resize my encrypted drives in order to use hibernation. I tested it out previously, and it tries to work, but fails since the 4G of swap space is too small. The partition order on the drive is efi, recovery, encrypted swap, then encrypted fs with two volumes and timeshift set up. I was able to follow a nice guide here: Pop!_OS 21.04: installation guide with btrfs-LVM-luks and auto-apt snapshots with Timeshift | Willi Mutschler to set things up, modified slightly to add a volume with nocow to house VM images. Looking at this page: ResizeEncryptedPartitions - Community Help Wiki leads me to believe that if I need to add more swap I will need to create a new encrypted partition with encrypted swap at the end of the drives, as there is a note about making sure that the resized partition starts at its original sector. I can follow this to a certain extent but the details get beyond me. My best solution if I really want to make use of hibernation likely is to pull any info off of the drive that I want to save, and start over, this time making the swap space sufficiently large. If I go that route I’ll likely set it to RAM + 2gb, in order to avoid any need to go through this again down the line.

Everyone seems to be focused on hibernation on Linux, but for anyone using Windows here’s something interesting I found. The default hibernation setting on my Framework laptop is to wait 596,523 1/3 hours before hibernating. I changed mine to 30 minutes.

2 Likes

This a setting conducive with S0 standby which the framework laptop and windows supports. In this mode the computer goes into low power when suspended, until 5% of the battery has been used sleeping, and then hibernation is activated. For this reason, your hibernation timer doesn’t really need to be altered.

Thanks for the thread/everyone, this has been on my checklist for a while. Gonna knock this one out in Fedora. Does anyone know to get similar Windows suspend-then-hibernate behavior in Linux?

Ideally both:

  • S0 suspend/sleep, then after X used percentage (e.g. 5%), hibernate
  • During S0 suspend/sleep, hibernate upon reaching some low battery percentage, e.g. 5%. If suspended at 7%, hibernate when laptop reaches 5%, not at 2% (7% minus the used 5% = 2%).

The Arch wiki covers both hybrid sleep and suspend-then-hibernate:

https://wiki.archlinux.org/title/Power_management#Hybrid-sleep_on_suspend_or_hibernation_request

The former “suspends the system both to RAM and disk, so a complete power loss does not result in lost data. This mode is also called suspend to both.”

The latter “initially suspends the system to RAM and if it is not interrupted within the delay specified by HibernateDelaySec in systemd-sleep.conf(5), then the system will be woken using an RTC alarm and hibernated.”

1 Like