5

I've been an Ubuntu user since version 9.04, and I'm wondering why hibernation on Ubuntu (and other Linux distributions) is so complicated.

Recently I installed 18.04. I tried several tutorials on the internet to make the system capable of hibernation, either by (a) clicking the menu and selecting the hibernate option, or (b) automatically hibernating when closing the lid of my laptop.

For the first case, I manged to get it working on my laptop after countless hours of researching, however I have yet to be able to get the get the second case working.

I tried:

  1. I installed the Hibernate status button GNOME extension.

  2. Edited /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla according to this answer here on AU.

  3. Edited my GRUB configuration to resume my UIID swap partition and then updated GRUB

  4. Edited /etc/systemd/logind.conf according to this answer here on AU.

Specs:

  • Dell G3 laptop
  • CPU: Intel Core i7 8550H
  • GPU: Nvidia GTX 1050TI
  • RAM: 16GB
  • SSD: SanDisk 240GB
  • HDD: 1TB (I think Seagate)
karel
  • 114,770
  • Recent Windows hasn't it enabled by default either. –  May 26 '19 at 15:11
  • I totally understand this feature disabled by default. But, in windows for instance, it's pretty easy and "plug and play" to enable. In Ubuntu/mint and others, you have to be almost a programmer to enable it. –  May 26 '19 at 16:47
  • I have payed attention to all requirements for hibernation to work, like the swap partition. It's not that the problem. –  May 26 '19 at 16:48
  • 2
    @jmath1983 what have you tried so far? Please [edit] your question and tell us which tutorials you have tried and what didn't work. – danzel May 26 '19 at 21:03
  • Sometimes hibernation acts up after kernel upgrade or power failure. Test this command: sudo rtcwake -m disk -u -t \date '+%s' -d '+ 2 minutes'`` – kenn May 28 '19 at 13:05
  • @jmath1983 I rolled it back to some intermediate version now. You should normally be able to do it yourself from the revisions page, I think. Anyway, thanks for your agreement. Please ask a separate question about the lid closing issue then. – Byte Commander May 28 '19 at 13:15

2 Answers2

4

Hibernation is not an easy thing to implement. As a matter of fact, Apple didn't implement hibernation on their Macs until 2005 (source), 5 years after Windows ME officially introduced hibernate in 2000, although Windows 95 and 98 supported it if the manufacturer provided hardware-specific drivers (source).

Basically, the way hibernation works is the kernel puts all process to sleep, dumps the contents of the RAM onto the disk, and then turns off the computer. Then when the computer is turned back on, the contents of the memory dump to disk is reloaded back into the RAM, and then the processes are awakened again.

This whole procedure is fraught with problems. For instance, what happens if the computer is hibernated when the filesystem buffer is not synced with the disk, and then you boot another OS when starting the computer back up? Well, that's how you get the "NTFS partition is in an unsafe state" error when dual booting Linux with a Windows install that was either hibernated or had "fast startup" enabled.

To make matters even more complicated, while the current implementation of hibernate on Windows creates a hiberfile.sys file on your C:\ drive to store the memory dump, the current Ubuntu implementation of hibernate needs a swap partition. However, as the configuration of the swap partition is dependent on the user's choices during install, some users might create a swap partition not large enough to hold the RAM dump, or others might choose to not use a swap partition at all!

Another thing to consider is that hiberation can take a long time. This is especially true if you have a beefy computer with lots of RAM. For instance, I have 24GB of RAM, and assuming a constant dump rate to disk at 120MB/s, it would take over 3 minutes to perform hibernation. Not to mention, resuming would take equally long. At that point, it would take an equal amount of time to shut down and restart.

Now of course, hibernation and resume from hibernation would be a lot faster if you have an SSD. However, dumping 24GB to your SSD repeatedly will not do great things for its life expectancy, as the NAND flash in the SSD can sustain only a limited number of program-erase cycles before it starts to degrade.

Overall, I think the answer as to why hibernation on Ubuntu is so complicated can be summed up as follows:

  • The actual technical process of hibernation and resume is very complicated and "there be dragons there"

  • It's not a feature in very high demand (e.g. I think a lot of other people, like myself, would like to see, for instance, Wayland (replacement for X11) finished rather than have hibernation.

  • I'm guessing a little bit here, but I'm going to go out on a whim and say that the drivers for GPUs and other devices probably have to be specifically written with hibernation in mind.

  • The meat of what you listed makes little sense as an answer to why it's so complicated. Buffers can be flushed easily. Time to hibernate, and SSD wear both matter, but can be left to user decision. Switching from partition to swapfile is trivial. I've been hearing regular complaints about suspend/hibernation for 20 years. Perhaps not a hot issue on the kernel mailing list, but not low demand from end user perspective. This issue has prevented large organizations from adopting linux laptops. The only part that holds water, IMO, is the very last part about hardware/GPU/device driver issues. – Catskul Nov 01 '22 at 16:21
  • There is no longer needed to have a swap partition, a file is enough. – Wodzu Aug 31 '23 at 07:37
2

Hibernate is not a smooth going feature at times due to the very nature of how it works and how the hardware must support it. If the SWAP partition is not set correctly, there could be data loss due to crash, and computer freeze at startup are common problems associated with Hibernation.

Typically, Linux needs the size of RAM for its SWAP size, but not everybody follows this in its entity, leading to the Hibernate problems. Ubuntu had Hibernate as a default feature in the Power panel, but since Ubuntu 12.04 LTS, the feature was dropped due to ever increasing problems reported by several users.

But it doesn’t mean your PC can’t hibernate anymore. All you need to do is first check if your computer hardware is compatible with the mode.

  • Have you seen the specs I mentioned in the post? Like I said, I'm not totally a beginner in Linux, so you can be sure I've read the requirements for hibernation to work, my swap partition exceeds a little the amount of RAM I have. –  May 26 '19 at 17:05