Linux suspend to ram

How can I suspend/hibernate from command line?

Traditionally ubuntu supported a fairly blunt method of suspend and hibernate. Neither would integrate well with other apps and sometimes not even work on some machines. This new method doesn’t require root and notifies all applications listening for power events.

Systemd Method

Starting with Ubuntu 16.04, systemctl call must be used (See Suspend command in Ubuntu 16.04)

New Method (obsolete)

Obsolete circa Ubuntu 16.04; use systemctl instead, as above.

See the answer here on this page from Adam Paetznick regarding the use of dbus. Ideally you would create a ~/bin/suspend shortcut/script that makes the use of this action easy.

Old Method

According to the Ubuntu Forum you can use the following commands:

This requires that you install the powermanagement-interface package (not tested).

sudo apt-get install powermanagement-interface

I have also found the commands sudo pm-suspend and sudo pm-hibernate to work on my netbook.

pm-suspend and pm-hibernate works for me and it’s easy. Requires sudo but that’s OK. (Found pmi idea before but installing a package to use suspend is well bad. )

The gnome-friendly way is to use dbus.

dbus-send --system --print-reply \ --dest="org.freedesktop.UPower" \ /org/freedesktop/UPower \ org.freedesktop.UPower.Suspend 

There are two advantages to this command over pm-suspend .

  1. It will lock your screen (upon resume) if you have that option selected in gnome.
  2. It does not require root privilege, so it is easy to add it as a keyboard shortcut, for example.

As mentioned in the comments exchanging the Suspend in the last line to Hibernate creates a hibernate command:

dbus-send --system --print-reply \ --dest="org.freedesktop.UPower" \ /org/freedesktop/UPower \ org.freedesktop.UPower.Hibernate 

If the hibernation throws Error org.freedesktop.UPower.GeneralError: not authorized your user might not be allowed to hibernate. Edit or create /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla so it contains the following section: (source)

[Re-enable hibernate by default] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes 

Note: This is basically the same as qbi’s answer, but updated to work for newer versions of Ubuntu as well as including hibernate.

Читайте также:  Linux tcp connection limits

Источник

Оцените статью
Adblock
detector