How to check if power management is configured in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if power management is configured on a Linux system. You will explore different methods to verify power management capabilities and settings.

Specifically, you will use the pm-is-supported command to check for supported power states like suspend-to-idle, suspend, and hibernate. You will also examine the /sys/power filesystem to understand the current power state and available power options. Finally, you will inspect the logind.conf file to see how systemd's logind service is configured for power management events.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/FileandDirectoryManagementGroup(["File and Directory Management"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/FileandDirectoryManagementGroup -.-> linux/cd("Directory Changing") linux/FileandDirectoryManagementGroup -.-> linux/which("Command Locating") subgraph Lab Skills linux/cat -.-> lab-558801{{"How to check if power management is configured in Linux"}} linux/cd -.-> lab-558801{{"How to check if power management is configured in Linux"}} linux/which -.-> lab-558801{{"How to check if power management is configured in Linux"}} end

Check power support with pm-is-supported

In this step, we'll explore how to check the power management capabilities of your system using the pm-is-supported command. This command is part of the pm-utils package, which provides simple command-line tools for suspend and hibernate.

First, let's check if the pm-is-supported command is available on your system. Type the following command in your terminal:

which pm-is-supported

If the command is found, you'll see the path to the executable, something like:

/usr/bin/pm-is-supported

If it's not found, you might see no output or an error message. In a typical LabEx environment, pm-utils should be installed, but it's always good practice to check.

Now, let's use pm-is-supported to see if your system supports suspend-to-idle. Suspend-to-idle is a power-saving state where the system remains in a low-power state while still being able to respond quickly to events.

Type the following command and press Enter:

pm-is-supported --suspend-to-idle

This command checks specifically for suspend-to-idle support. The output will indicate whether it's supported or not. You might see output like:

suspend-to-idle

This means suspend-to-idle is supported. If it's not supported, there might be no output or a different message.

You can also check for other power states like suspend (suspend-to-RAM) and hibernate (suspend-to-disk).

Try checking for general suspend support:

pm-is-supported --suspend

And for hibernate support:

pm-is-supported --hibernate

The output will tell you if these power states are supported on the system. Understanding which power states are supported is important for managing system power consumption.

Click Continue to proceed to the next step.

Verify power state in /sys/power

In Linux, the /sys filesystem provides a way to interact with the kernel and get information about the system's hardware and state. The /sys/power directory contains files related to system power management.

In this step, we will examine the contents of the /sys/power/state file to understand which power states are currently available on the system.

First, let's navigate to the /sys/power directory. While you can view the file from your current directory, changing directory helps you understand the file's location within the filesystem hierarchy.

Type the following command to change your current directory:

cd /sys/power

Now that you are in the /sys/power directory, you can view the contents of the state file. We'll use the cat command, which is used to display the content of files.

Type the following command and press Enter:

cat state

The output of this command will show a list of power states supported by your system's kernel and hardware. The states are typically listed separated by spaces. You might see output similar to this:

freeze mem disk

Let's break down what these states generally mean:

  • freeze: This corresponds to suspend-to-idle. The system enters a low-power state, but the CPU is still active in a low-power mode, allowing for quick wake-up.
  • mem: This corresponds to suspend-to-RAM. The system saves its state to RAM and enters a very low-power state. Waking up from this state is relatively fast.
  • disk: This corresponds to suspend-to-disk, also known as hibernation. The system saves its state to the hard disk and powers off. Waking up from this state takes longer as the state needs to be read back from the disk.

The states listed in your output are the ones that your system is configured to support at the kernel level. This information complements what you learned from the pm-is-supported command in the previous step.

You can now change back to your home directory if you wish, although it's not strictly necessary for the next step.

cd ~

Click Continue to move on.

Inspect logind config with cat /etc/systemd/logind.conf

In this final step, we will look at the logind.conf file, which is the configuration file for systemd-logind. systemd-logind is a system service that manages user logins, sessions, and seats. It also handles power and suspend key presses and lid switches.

The logind.conf file is located in the /etc/systemd directory. We will use the cat command again to view its contents.

Type the following command and press Enter:

cat /etc/systemd/logind.conf

This command will display the content of the logind.conf file. This file contains various settings that control the behavior of systemd-logind. You will see lines starting with #, which are comments and are ignored. Lines without # at the beginning are configuration options.

You might see options related to power management, such as:

#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#StopIdleSession=no
#IdleAction=ignore
#IdleActionSec=30min
#InhibitDelayMaxSec=5min
#UserStopDelaySec=10
#KillUserProcesses=no
#KillExcludeUsers=root
#OOMScoreAdjust=-1000
#RuntimeDirectorySize=10%
#RuntimeDirectoryInodes=400k
#RemoveIPC=yes
#Inhibitors=block
#SessionsPerUser=0
#RemoteUserControl=no

These commented-out lines show the default settings. If a line is uncommented (does not start with #), it means that setting has been explicitly configured.

For example, the HandlePowerKey option determines what happens when the power button is pressed. The default is poweroff. HandleSuspendKey and HandleHibernateKey control the behavior of suspend and hibernate keys, respectively. HandleLidSwitch controls what happens when a laptop lid is closed.

By examining this file, you can understand how your system is configured to respond to various power-related events. While you won't be modifying this file in this lab, knowing its location and purpose is valuable for understanding system power management in Linux.

You have now completed this introductory lab on checking power support and configuration in Linux.

Click Continue to finish the lab and see your summary.

Summary

In this lab, we learned how to check the power management configuration in Linux. We started by using the pm-is-supported command to determine which power states, such as suspend-to-idle, suspend (suspend-to-RAM), and hibernate (suspend-to-disk), are supported on the system. This command, part of the pm-utils package, provides a quick way to assess the system's power management capabilities.

We then explored the /sys/power directory, which provides a kernel interface to verify the current power state and available power management options. Finally, we inspected the /etc/systemd/logind.conf file to understand how systemd-logind is configured to handle power-related events like lid closing or power button presses, which directly influence the system's power management behavior.