Console commands to hibernate and standby / sleep Linux machines

It’s great that Linux nowadays supports all the power management features available on computers. But it’s odd that beside the buttons to trigger standby/hibernate – which are only available in a graphical interface – there are no simple console commands to put the computer to sleep or into hibernation.

Standby and hibernation are very useful on (personal) servers in case of long power failures (of course, while using an UPS). This way the server can put itself to sleep – while retaining all running stuff (especially running virtual machines, which take ages to boot and close) ready to be restored when the power returns.

So the two (not so simple) console commands are:

Hibernate

echo disk > /sys/power/state

 

Standby/Suspend to memory (S3 or S1, depending on BIOS settings)

echo mem > /sys/power/state

 

The best way to prepare you system for future usage of these commands is to create two script files, namely standby and hibernate (with the appropriate content) and chmod them 755.

 

They are also another 2 states (4 in sum) and they are:

state:		Suspend-To-Idle
ACPI state:	S0
Label:		"freeze"
State:		Standby / Power-On Suspend
ACPI State:	S1
Label:		"standby"
State:		Suspend-to-RAM
ACPI State:	S3
Label:		"mem"
State:		Suspend-to-disk
ACPI State:	S4
Label:		"disk"

Not usually all supported from older hardware, you can check the kernel notes here

To see which of them are supported you can use:

cat /sys/power/state

You will see output like that:

[root@freedom ~]# cat /sys/power/state
freeze mem disk

 

Leave a Reply