Add to that difficulty the fact that many hardware (peripheral) vendors provide incomplete documentation making it difficult or impossible to implement "off-nominal" situations like hardware state reading/writing-restoring.
VMs have an advantage that the peripherals are limited in types and numbers and the state is "virtual" so the state is directly accessible (r/w) in the virtualizing driver software, not buried in physical hardware. When you "hibernate" a VM, no physical device actually powers down and no (buried in hardware) state is lost.
I have a ThinkPad running Archlinux. I have suspend-then-hibernate mode enabled, which means when I close my laptop lid it suspends for 2 hours (configurable) and then puts itself into hibernate. If I decide to open the laptop within 2 hours, it's available instantly. Otherwise, it takes maybe 20 seconds to reanimate from hibernation. People often say, why not just shutdown and reboot? The obvious answer is that I don't want to close out a dozen Chrome tabs, close all my terminals, all my files, and open everything up every time I need to walk away from the computer.
I have secure boot turned on. Hibernation is done to a swap file (I can simply delete the file if I need the space). I have LUKS encryption enabled. I'm dual booting with Windows. And yes, it all does work perfectly fine.
You can have your cake and eat it too. It just takes a bit of research and a bit of time to setup.
I switched the SSD of my MBP 2 years ago and since then everything is out of control. Sometimes the thing keeps running when I close the lit and when I open it again the battery is empty. Sometimes it simply shuts down entirely and has to boot from scratch when I open it again.
I tried reinstalling the OS and whatnot, nothing worked.
With SSDs, booting is fast. Most apps that I care about which have complex state (browser, IDE) do a much better job of saving their state than the OS can do (browsers & IDEs can and do easily restore sessions, etc).
Discussed in HN: https://news.ycombinator.com/item?id=26285683 (113 points, 39 days ago, 64 comments)
This makes a huge difference on Linux, and I hear the windows mode is somewhat experimental and not working so well yet even with Windows.
https://mobile.twitter.com/dorfsmay/status/13629639921094778...
You can see some discussion here: https://bugs.launchpad.net/ubuntu/+source/policykit-desktop-...
and even more here: https://bugs.launchpad.net/ubuntu/+source/policykit-desktop-...
net/net even back then, no matter how much effort we put into it, we could never make it work on even most machines because there was just too much variability. The OEM team could make it work for specific machines that Ubuntu was pre-installed on, but otherwise, hibernate was just a bug farm.
Regularly my MBP dies with the lid closed with no option to hibernate. After which, it refuses to start for 15 minutes after being plugged in, before it agrees to turn on. To me, that is user hostile.
Windows hides the hibernate option until you do some magic incantation. Often upon restart, wifi driver is disabled or cannot be enabled and I have to restart.
On Linux, At least with a decent swap size, all I have to do is `systemctl hibernate` and it works like magic. LUKS and sd-boot are what I use as well.
I can't, however, easily find an explanation of how actual hibernation is different from this simplistic understanding.... would someone care to explain?
Sleep works fine for ages. Works better on Linux on my 2015 laptop than on Windows (hint: if you have a KIRA laptop, suspend stops borking after you update the drivers for the touchpad to a ~2019 version).
I have a LUKS (but not LVM) encrypted root and swap partition on /dev/sda3 and /dev/sda4 respectively.
I use the command "su && mount /boot && genkernel --luks initramfs" to generate the initramfs.
I give the initramfs the following parameters: "crypt_root=/dev/sda3 root=/dev/mapper/root crypt_swap=/dev/sda4 resume=/dev/mapper/swap". This makes my initramfs ask for my password for the partitions, then decrypt the partition, then mount them and resume from hibernation if possible.
I add this parameter by setting GRUB_CMDLINE_LINUX in /etc/default/grub, and then running "grub-mkconfig -o /boot/grub".
When I want to hibernate I use the following command: "exec loginctl hibernate". My window managers let me bind this to a keyboard combination.
I am using openrc as my init system (with elogind), and sway/GNOME as my window manager. The computer uses legacy BIOS (SeaBIOS) and the storage uses GUID partition table with the grub bootloader. Hope this helps.
The technical linux communities, like Redhat, Suse or Arch figured it out. See eg https://www.ctrl.blog/entry/fedora-hibernate.html
Of course app developers can make a restart less painful too. Web browsers have already implemented restoring tabs from the last use, and Outlook will automatically save any of your drafts. For any work in the cloud, you really just need a pick up where you left off cue.
Every time my desktop PC running Windows 10 tries to wake up from a suspend-to-disk or even suspend-to-RAM state, it resets its BIOS and RTC.
Hibernation is not a very viable scenario for me. I have uses for a 64 GiB chunk of my solid state storage, thank you very much.
Back then the consensus was that it's a really hard problem for all sorts of reasons (including but not limited to proprietary hardware, crappy hardware, etc.), which of course it is, but that given a few years and the shallowness of all bugs under the collective eyeballs of the entire Linux community it was inevitable that it would eventually become rock solid. I just remember a lot of people being really really really insistent about it, and when sophomore CS undergrads on Slashdot are really insistent about things being true then you know it must be true. I'm seeing the same advice here today, so you're in luck! Give it a couple years, it'll be fine. Either that or "Windows doesn't do it that great either". Either that or "nobody actually needs to use power management features and if you do you are computering wrong". Either that or "I've never had a single problem with power management on Linux but I've had tons of problems with it on macOS and Windows so there!" Aren't you glad you asked?!?
I think distros don't ship with it by default because it's still slightly tricky to get right in some cases. Hibernating on some hardware can crash or lock your machine. Remember that most Linux distros are still just a puddle of random tools and glue; it's never going to be as polished as a commercial OS.
If a laptop that won’t hibernate is a defect, it’s a manufacturing defect.
It’s not the fault of volunteers working on a free operating system.
0. This is a highly unusual operation. There is no other code that exercises this scenario of switching form a hot state to another hot state, not even S3 sleep or runtime suspend (AKA s0ix, or PCI D3 Hot) although they are a little similar. You need to completely freeze the hardware (including invalidate every cache, stop all firmware, etc), then switch to the other Kernel and make sure this other Kernel can resume operation from the state the hardware is, which is probably different from the state left at boot or at S3.
1. AFAIK the hardware (BIOS, firmware, etc.) cannot detect this as well as it can detect, for example, S3, so it can not properly react. I know, sometimes hardware/firmware gets in the way, but sometimes it helps by setting state your driver may not otherwise be aware it needs to set.
2. Testing S4 is a pain. Basically if you want to guarantee S4 works you have to put the machine to S4, wake it up, run your whole test suite again, then put to S4 and wake up a few more times and then test again. Some bugs don't show up in the first S4 cycle.
3. Debugging S4 is even worse, since it involves two different Kernels and a lot of wasted time checking for everything. Do you think devs run S4 cycles before sending patches to the mailing list?
4. With machines booting so fast and both S3 and runtime suspend working so well (not necessarily on Linux), there is little reason to even want to hibernate. Seriously, why would I ever want to use S4?
4.5. Colorary: S4 bugs will always be very low priority for the devs I pay, unless I have a paying client explicitly yelling about it.
5. Every driver in your system needs to be properly working. Just a single broken driver may screw everything in your S4 cycles. So unless you're running on a machine where some dev team explicitly tested S4 to make sure it works, then there's a chance it won't work properly.
6. It's not impossible to get this right, it's not impossible to architect drivers so the S4 code benefits from the S3 code. It's not impossible to architect a driver so it's properly initialize and work on whatever state the registers are. But it's just almost never the priority to ensure S4 works.
Edit:
The driver I worked on was nicely designed and we tried to take advantage of S3 for S4 as much as we could. Still, sometimes an S4 bug would appear and would result in tons of debugging hours just for it. I remember one specific case where the hardware got a new cache and we forgot to invalidate it before switching, and that caused very weird memory corruption. We wasted probably 2 "man months" in debugging hours before the one line fix was committed. We had a client that was doing like 50 S4 cycles in their test procedures, and the bug for some reason would only appear after 2 S4 cycles.
If you shut down the computer when it's not in use, the problems stated never happen. That's not a solution everyone will use, I guess, but it completely eliminates the problems and is very simple to do. I wish more problems had "simple and complete" solutions :-).
https://austingwalters.com/increasing-battery-life-on-an-arc...
Effectively it will idle for 2 hrs and if I don’t reopen the lid it’ll shut down (saving state to disk). Works really well, boot up is slower than I’d like, but battery life is great. Pretty happy, tbh.
Through there is some hardware for which you will have a hard time to make hibernation work and the only reason why it works on windows is because the vendor explicitly provided a proprietary/closed source driver for their hardware.
And besides this there is the simple reason that Linux is server first. Servers generally don't do hibernation.
[0] https://www.asus.com/au/Displays-Desktops/Mini-PCs/All-serie...
Honestly, it would probably be easier to just run everything off a VM if having persistent states matters to you.
References: https://wiki.archlinux.org/index.php/Power_management/Suspen...
https://blog.ivansmirnov.name/how-to-set-up-hibernate-on-ubu...
If you stick to “common” hardware and a high quality distribution you should be fine.
TL,dr: Set up large enough Swap and configure Grub correctly
Intel doesn't need it to sell chips.
The Linux kernel is huge, complex and particularly messy in terms of internal structure. This makes even otherwise trivial modifications hard, and complex modifications extremely hard. The development overhead is brutal.
And hibernation just happens to be a scenario that's a nightmare to implement with such a design.