Linux hibernate command line

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.

Источник

How to boot, shut down, and suspend your system from the Linux command line

Learn how to schedule timed shutdowns and reboots with systemd and to hibernate your system with systemctl.

Sysadmin working on three monitors in dark room

Let’s face it: The most fundamental thing we do with computers is turn them on and off. Everything else happens between those two particular events. And sometimes, restarting the system is a key component of troubleshooting or completing installation processes.

Training & certification

Typically, you need root privileges to shut down or reboot the system. Ensure your account is configured in /etc/sudoers for this authority. Remember, it’s generally a bad idea to log on directly as root.

Читайте также:  Linux usb web camera

Boot the system

Starting the system is as simple as pressing the power button. What happens from there varies a bit depending on your hardware, but in general, the process looks like this:

  1. The firmware (BIOS or UEFI) finds the boot media.
  2. The boot loader starts, and the Master Boot Record (MBR) or GUID Partition Table (GPT) loads.
  3. The operating system selection menu appears.
  4. The boot loader stage 2 starts and loads the selected kernel.
  5. The kernel and drivers load and mount the root filesystem.
  6. systemd launches as PID 1.
  7. The default.target file loads.
  8. The user is prompted to authenticate.

The system launches to the default.target (providing either a command-line interface or graphical environment). Changing these targets is outside the scope of this article but is something I cover in How to switch between the CLI and GUI on a Linux server.

Shut down the system

When Red Hat Enterprise Linux (RHEL) adopted systemd with RHEL 7, what happened to the venerable Linux shutdown command? It remains—but now it maps to systemd’s shutdown functions.

The shutdown command features two options: —halt and —poweroff . The —halt option stops the operating system while the —poweroff option turns off the system.

One of the main benefits of the shutdown command is the ability to define a shutdown delay to give users time to save their work and log off the system. Schedule a time that suits your needs by using the format hh:mm (24-hour time designations).

For example, to halt the system at 10pm, type:

It’s more likely that you’ll want to halt the operating system a few minutes into the future. In that case, specify the number of minutes from now to begin the shutdown process.

For example, to halt the system after a five-minute delay, type:

You can append a message to all users by entering it after the time specification, like this:

$ sudo shutdown --halt +5 “Attention. The system is going down in five minutes.”

Cancel a timed shutdown by using the -c option:

IT Automation ebook

You can also use the systemctl command to shut down the system. For example, type systemctl halt or systemctl poweroff to achieve similar results to the shutdown command. The main disadvantage of using systemctl is losing the ability to schedule or cancel the shutdown process.

Reboot the system

When someone approaches you for help with their computer, I suspect one of your first responses is, «Did you reboot it?» Restarting a computer helps with various problems and may even be necessary to finalize some configurations. However, restarting is considered downtime on a server and should be avoided if possible. Try to use systemctl restart to restart services rather than reboot the whole system.

However, sometimes a restart is inevitable. The option for restarting the system immediately with the shutdown command is -r , so it looks like this:

You can still specify a delayed time using the hh:mm format explained above.

Читайте также:  Linux нет стабильных дистрибутивов

You can also use systemctl to reboot the device by typing:

Again, the disadvantage with systemctl is the inability to delay the process.

Suspend the system

Great Linux resources

There are a couple of ways to place the system in a reduced or no-power mode. The first is suspend and the second is hibernate.

When you suspend the system:

  • Contents of memory are moved to the swap location.
  • The boot loader is configured to boot directly to the current kernel.
  • The system shuts down (no-power mode).
  • Upon power up, the system reloads itself from swap.

When you hibernate the system:

  • Applications are stopped.
  • System state is moved to RAM.
  • The system remains powered on in a low-power state.

You can also suspend and hibernate the system by using the systemctl command. The commands are exactly what you’d expect:

$ sudo systemctl suspend $ sudo systemctl hibernate $ sudo systemctl hybrid-sleep

The systemctl hybrid-sleep command both suspends and hibernates the system.

Use the GUI

Depending on the graphical user interface (GUI) environment you have installed, you can initiate a reboot or shutdown from a menu. Many people rely on a graphical desktop like GNOME, so this is certainly a viable option.

Power off and log out options in GNOME

[ Because sudo is something you don’t configure often, it can be hard to remember its nuances. Download the Linux sudo cheat sheet. ]

Wrap up

The familiar shutdown command now maps to systemd and executes timed shutdowns and reboots. You can use systemctl if you wish, but being able to schedule the shutdown is helpful. In addition, systemctl also offers suspend and hibernate options. Try to avoid bringing down the system when possible, but sometimes it’s necessary.

Источник

Difference between suspend and hibernate in Ubuntu and how to execute them from command line

Computer Dreaming

Exploring the differences between suspending, hibernating and shutting down a computer with Ubuntu. In Ubuntu, power management commands are handled with systemd services. “systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.” 1 and services are simply unit configuration files whose name ends in .service . systemd environment.

Options

  • Power Off
    • “Print a wall message to all users, shut down and power-off the system.” 2
    • “Print a wall message to all users, shut down and reboot the system.” 3

    The basic idea of putting a computer to sleep is to change its state into a “pausing mode”, so when we resume its operation, we have the same applications running and files opened as we had before sleep.

    Main strategies involves using volatile storage like or non-volatile memory

    TL;DR

    Suspend saves its state to the RAM , hibernation saves it to disk.

    Suspension is quicker but doesn’t work when running out of energy, while hibernating can deal with running out of power but it is slower.

    Differences chart

    # Suspend / Sleep Hibernate
    Saves state into RAM HDD
    Requirements Continuous power supply. Swap space.
    Power consumption Low None
    Resume time Fast. Recovers data from RAM Slow. Has to deal with disk’s lower response time.
    Risk of data loss In a power outage No risk. Data is saved in non-volatile storage

    Suspend

    Suspend means basically to **Suspend to RAM ** to consume less energy.

    when placed in sleep mode, the computer cuts power to unneeded subsystems and places the RAM into a minimum power state, just sufficient to retain its data. Because of the large power saving, most laptops automatically enter this mode when the computer is running on batteries and the lid is closed

    Wikipedia article Sleep mode

    From command line it can be called with: systemctl suspend

    • systemd files
      • service: /lib/systemd/system/systemd-suspend.service
      • execs /lib/systemd/systemd-sleep suspend

      Hibernate

      Hibernate, or Suspend to Disk, “is powering down a computer while retaining its state”. 4

      saves all computer operational data on the fixed disk before turning the computer off completely. On switching the computer back on, the computer is restored to its state prior to hibernation, with all programs and files open, and unsaved data intact. In contrast with standby mode, hibernation mode saves the computer’s state on the hard disk, which requires no power to maintain, whereas standby mode saves the computer’s state in RAM , which requires a small amount of power to maintain

      Wikipedia article Sleep mode

      From command line it can be executed with: systemctl hibernate

      • systemd files
        • service: /lib/systemd/system/systemd-hibernate.service
        • execs /lib/systemd/systemd-sleep hibernate

        Hybrid

        hybrid-sleep Hibernate and suspend the system

        A third approach is to suspend to copy the contents to RAM , and then hibernate which would also copy the contents of the RAM to the disk, so the power on is faster than powering on a computer and restoring the state manually.

        From command line it can be executed with: systemctl hybrid-sleep

        • Sleep
          • service: systemd-hibernate.service/systemd-hybrid-sleep.service
          • execs /lib/systemd/systemd-sleep hybrid-sleep

          Suspend & hibernate

          “Suspend the system, wake after a period of time and put it into hibernate” 5

          From command line it can be executed with: systemctl suspend-then-hibernate

          • Suspend & Hibernate
            • exec /lib/systemd/systemd-sleep suspend-then-hibernate
            • service: /lib/systemd/system/systemd-suspend-then-hibernate.service

            Summary

            • To suspend from command line: systemctl suspend .
            • To hibernate: systemctl hibernate .
            • An hybrid approach: systemctl hybrid-sleep
            • Suspend and hibernate: systemctl suspend-then-hibernate

            References

            Marcelo Canina

            I’m Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.

            Articles

            • How to activate tap to click touchpad’s feature in Ubuntu in 4 stepsMarch 4, 2021
            • Difference between suspend and hibernate in Ubuntu and how to execute them from command line
            • Solving Google Chrome’s gpu-process error message in Ubuntu LinuxJanuary 7, 2019
            • Solving Google Chrome’s secret service operation error message in Ubuntu LinuxJanuary 7, 2019
            • Start Emacs In Ubuntu The Right WayJune 10, 2017

            Differences between power management commands in Ubuntu Linux.

            Simple IT 🤘 Rocks

            Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

            Источник

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