Bug 474979

Summary: Add a feature in the Power KCM to setup/enable Hibernation
Product: [Applications] systemsettings Reporter: Justin Zobel <justin.zobel>
Component: kcm_powerdevilAssignee: Plasma Bugs List <plasma-bugs-null>
Status: CONFIRMED ---    
Severity: wishlist CC: davide, kde, kdedev, natalie_clarius, nate, ngompa, nilskemail+kde
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Justin Zobel 2023-09-28 12:05:01 UTC
Discussed in the Fedora KDE SIG Matrix channel.

Setting up hibernation with the myriad of file systems and methods out there isn't a simple task for a user.

Plasma's Power KCM could offer the user options to set up hibernation including working with file systems to ensure it is set up correctly e.g. BTRFS subvolumes.
Comment 1 Neal Gompa 2023-09-28 12:21:42 UTC
Let me go a step further here: we could just dynamically create a swap file whenever hibernation is enabled.

On Btrfs, all that's required to do is the following:

$ truncate -s 0 swapfile
$ chattr +C swapfile
$ fallocate -l 32G swapfile # set this to just slightly larger than how much RAM is on the system
$ chmod 0600 swapfile
$ mkswap swapfile
$ swapon swapfile

Ideally, this swap file exists in a Btrfs subvolume that has "chattr +C" set on it, because we can use that subvolume to create more swap files as needed for performance.
Comment 2 Natalie Clarius 2023-09-28 15:17:38 UTC
But setting up a swap file is just half of the work, right? You still need to tell the kernel about it: https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation Not sure if it works differently between different distributions also. So yes, sounds like something nice, but also non-trivial to implement.
Comment 3 Justin Zobel 2023-09-29 00:44:48 UTC
With some things like disk changes, you can update the kernel about it with certain commands. I wonder if you can do that with Hibernation as well.
Comment 4 Neal Gompa 2023-09-29 02:13:48 UTC
You can use "grubby" in Fedora to do that easily and persistently. 

$ grubby --update-kernel=ALL --args=”<new cmdline args>”

Other distributions may either have a commandline tool or just rely on updating /etc/default/grub. Probably the correct way to deal with this is provide a hook that a distribution can fill in with a script/command/etc. to handle it.
Comment 5 Justin Zobel 2023-09-29 02:34:41 UTC
That's a good idea, it could be a file on the system or something added at compile time.

The file if detected would then show the Hibernation settings in the KCM.

The file would contain the commands necessary to enable and disable hibernation on that particular OS.
Comment 6 Davide Cavalca 2023-09-29 19:48:31 UTC
In case it's helpful, we have an implementation of the swap setup and management dance in https://github.com/facebook/chef-cookbooks/tree/main/cookbooks/fb_swap . While this won't be directly usable for this purpose, the systemd logic in there can likely be cribbed, or at least used as inspiration.
Comment 7 Neal Gompa 2025-11-01 18:58:03 UTC
There's also a slightly scary implementation that has been proposed to KDE Linux: https://invent.kde.org/kde-linux/kde-linux/-/merge_requests/281

I don't think it's an appropriate solution, but it does outline the mechanical steps for this.
Comment 8 TraceyC 2025-12-08 23:25:38 UTC
Given that this has has some discussion of ways forward, marking confirmed