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.
sudo rtcwake -m disk -u -t \
date '+%s' -d '+ 2 minutes'`` – kenn May 28 '19 at 13:05