2

I managed to resize my LVM partitions, set up my swapfile, and disable secure boot, so now I can hibernate with sudo systemctl hibernate. However, I want to be able to hibernate from my power menu (wlogout) without needing to use sudo. The systemctl commands suspend, reboot, and poweroff all work without needing sudo. Why does hibernate require sudo, and is there a way to drop it, so I don't need to interact via the command line for this one power option?

Using:

  • Ubuntu 24.04 LTS
  • Sway WM (not GNOME)

1 Answer 1

3

This is NOT something I am particularly familiar with but in the absence of answers from better-informed users...

Typically integration between desktop and shutdown (along with some other stuff) is handled via polkit. IMHO, polkit is not well documented. However the Arch Wiki does have some useful stuff which includes the specific example of how to disable hibernate. Hence for your scenario, something like....

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.suspend" ||
        action.id == "org.freedesktop.login1.suspend-multiple-sessions" ||
        action.id == "org.freedesktop.login1.hibernate" ||
        action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ||
        action.id == "org.freedesktop.login1.hibernate-ignore-inhibit")
    {
        return polkit.Result.YES;
    }
});

This should be redundant as the default policy should allow users to invoke hibernate. The default policy should be in /usr/share/polkit-1/actions/org.freedesktop.login1.policy. It is possible that "Sway" tries to do something unusual to invoke hibernate. You can test the D-Bus/polkit mechanism using systemctl suspend-then-hibernate at the shell.

2
  • Since I'm using systemctl to invoke hibernate, is the window manager even involved? How can I tell if I'm using polkit? Commented Jun 8, 2024 at 18:11
  • "not well documented" - an understatement if ever I saw one :-( Commented Jun 8, 2024 at 21:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.