sodcalculator

10 Tech How-To

Hibernate or Sleep Linux From the Command Line

Guide 10-39664 · Updated · Step by step

Linux can suspend a computer to conserve power or hibernate it by saving the current session to storage and powering off. Use systemd’s systemctl commands from a terminal; availability depends on your distribution, hardware, and power configuration, so save open work before testing either mode.

What You’ll Need

  • A Linux system that uses systemd, with access to a terminal.
  • Permission to request power-state changes. On many desktop systems, an active logged-in user can do this; a server or restricted session may require sudo.
  • For hibernation, working swap space and a system configured to resume from it. A swap file or partition alone does not guarantee hibernation will work.
  • Save your work and close anything that cannot safely be interrupted. Unsaved data can be lost if a command or resume fails.

Step-by-Step

  1. Check that systemd is in use. Run ps -p 1 -o comm=. If the output is systemd, continue with the commands below. Other init systems may use different tools; do not assume systemctl applies.
  2. Save work and choose a mode. Sleep is usually the right choice for a short break: it keeps the session in memory and resumes quickly, but continues to use some power. Hibernation saves the session to storage and powers down, using little or no operating power, but takes longer and needs correctly configured resume support.
  3. Try sleep (suspend) first. Run systemctl suspend. The screen should go dark and the machine should enter a low-power state. Wake it using the power button, keyboard, or lid, depending on the device. A desktop environment may also provide a sleep menu, but the command is useful for testing the system service directly.
  4. Use elevated permission only if needed. If the command reports that authorization is required or access is denied, try sudo systemctl suspend and enter your password when prompted. Do not add sudo reflexively: desktop policy may already authorize the logged-in user, and some systems intentionally restrict power operations.
  5. Check hibernation prerequisites before attempting it. Run swapon --show to see active swap, and cat /sys/power/state to see power states the kernel exposes. The latter may list disk, which is commonly associated with hibernation, but its presence alone does not prove that saving and resuming are correctly configured. A suitable swap area and boot-time resume configuration are also required. If you did not configure these, use sleep rather than treating a failed hibernate command as a safe test.
  6. Request hibernation when it is supported and configured. Run systemctl hibernate. If authorization is denied, try sudo systemctl hibernate. The machine should save its session and power off; start it again normally and allow the resume process to finish. Do not interrupt power while it is saving or restoring the session.
  7. Use hybrid sleep only if you understand the setup. systemctl hybrid-sleep combines suspend with a hibernation image, providing a potential recovery path if power runs out. It relies on working hibernation support as well as suspend, so it is not a workaround for missing swap or resume configuration. If your distribution supports it and it is configured, you can try sudo systemctl hybrid-sleep.
  8. Verify the outcome. After waking or restarting, check whether your session and open work were restored. If the command failed or the system restarted without restoring the session, record the exact message and investigate logs and hibernation configuration before trying again.

Common Mistakes

  • Confusing sleep with hibernation. systemctl suspend keeps the session in memory; it is not a full power-off. systemctl hibernate attempts to save the session to storage before powering down.
  • Assuming installed swap means hibernation works. Swap must be suitable for the saved image, and the system must know where to find that image during boot. Encrypted swap, a swap file, or changes to storage layout can require additional setup.
  • Closing the lid and assuming the command ran. Lid behavior is managed separately and can be configured to do nothing, suspend, or another action. Run the explicit command when you need to know which operation was requested.
  • Using sleep where power may disappear. A sleeping computer still depends on memory retaining its contents. If its battery drains or power is lost, unsaved session state can disappear.
  • Forcing a power-off after a slow resume. Hibernation can take time, particularly with a large session or slow storage. Interrupting it may lose the saved state or risk filesystem problems.

Tips

  • Use systemctl suspend for a quick break and reserve hibernation for longer periods when the system has been configured and tested.
  • Check systemd’s interpretation of each operation with systemctl status after a failure, and inspect recent system logs using journalctl -b -u systemd-suspend.service for suspend-related problems. Service names and useful log details can vary by distribution.
  • For a brief overview of active swap, use free -h or swapon --show. These commands report memory or swap status; they do not configure resume support.
  • Keep a copy of important work somewhere persistent before testing hibernation, especially after changing kernels, boot settings, encryption, or swap configuration.

Troubleshooting

“Unit not found,” unsupported operation, or no state change: Confirm that systemd is PID 1 and that the machine supports the requested state. Check cat /sys/power/state and recent logs with journalctl -b. A virtual machine, firmware setting, driver, or hardware limitation can prevent sleep or hibernation.

Permission denied: Try the appropriate command with sudo if you administer the machine. On a managed computer, ask its administrator rather than changing authorization policies.

Hibernation fails or boots to a fresh session: Check swapon --show, then review your distribution’s instructions for the kernel, bootloader, swap location, and resume configuration. Do not guess at boot parameters: an incorrect resume target can prevent restoration or cause boot problems. If swap is encrypted or a swap file is used, follow the instructions for that specific configuration.

Sleep starts but waking causes a freeze, blank screen, or immediate wake: Save work, reboot if needed, and review logs from the previous boot with journalctl -b -1. Check for available system and firmware updates through your distribution’s normal process. If the issue persists, use the desktop’s supported power options and report the hardware model and relevant log messages to your distribution’s support channel.

The laptop wakes as soon as it sleeps: A connected device, network wake setting, lid switch, or scheduled event may be triggering wake-up. Disconnect unnecessary peripherals and check the desktop or firmware power settings. Avoid disabling devices or editing kernel settings without identifying the cause.

Frequently Asked Questions

What is the command to put Linux to sleep?
On a system using systemd, run systemctl suspend. Use sudo systemctl suspend if your account is not authorized.

What is the command to hibernate Linux?
Run systemctl hibernate, or use sudo systemctl hibernate if required. Hibernation only works when swap and resume support are configured correctly.

Does hibernate turn the computer off?
It is intended to save the session to storage and power down. It differs from a normal shutdown because the system attempts to restore that saved session when it starts again.

Can I hibernate without swap?
Most Linux hibernation setups need a suitable place to store the memory image, commonly swap. Requirements depend on the distribution and configuration; check its documentation before changing storage settings.

Is sleep safe if my laptop battery runs out?
Sleep keeps the session in memory, so loss of power can lose unsaved work. Save important files first; consider properly configured hibernation for longer periods away from power.

How do I cancel a sleep command?
Once the system has entered sleep, wake it using the power button or another configured wake method. A command already in progress may not be cancellable from the sleeping session.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →