Search

Putting system to hibernate from the command line

Ever wanted a script to put your system into hibernation, well yes its available.

/etc/acpi/hibernate.sh  (if you are using acpi).

You would need to have root privileges to run the script. If you run the following from your command line

sudo /etc/acpi/hibernate.sh 


It will put your system into hibernation.

The script basically checks whether your system has 'acpi" support.


test -f /usr/share/acpi-support/state-funcs || exit 0

Then its runs a few scripts that will set various environment variables




. /etc/default/acpi-support
. /usr/share/acpi-support/power-funcs
. /usr/share/acpi-support/policy-funcs




Then it will check if these variables are set properly and use the command "s2disk " if it is available


if [ -x /sbin/s2disk ]


 or use

echo  -n "disk"  >/sys/power/state. 

which means that the state of your machine is being written on to the disk, and the power to the cpu will be cut off. Once the power is restored this state will be read back from the disk and the system will be restored to the exact same state as before.

You can use this script with the crontab to put your system to hibernate automatically after a few hours, or at a specific time in the night.

No comments:

Post a Comment