M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
ASIX1
Practical Exercise 10b: Basic power management 15-02-19

Practical Exercise 10b: Basic power management

GENERAL CONDITIONS
1- Deadline: 15-2-2019.
2- You do not have to send any report but questions abouts this exercise could be asked in the 2n and final exams.

1- Shutting down and restarting the system

To shut down a running Debian GNU/Linux system, you must not reboot with the reset switch on the front or back of your computer, or just turn off the computer. Debian GNU/Linux should be shut down in a controlled manner, otherwise files might get lost and/or disk damage might occur. In order to shut down your system in a controled manner, you can select one of the following options:

a)
If you run a desktop environment, there is usually an option to log out available from the application menu that allows you to shutdown (or reboot) the system.

b)
You can press the key combination Ctrl+Alt+Del.

c)
Another option is to log in as root and type the command systemctl poweroff to shut down and poweroff the system. If you run this command,  all remaining file systems are unmounted, all remaining swap devices are disabled, detached all remaining storage devices are detached,  all remaining processes are killed, cpu is halted (doing nothing) and finally, the system is powered off, in other words, the power supply is disconnected.

d)
You can also run the command systemctl halt to shut down and halt the system. If you run the command, all remaining file systems are unmounted, all remaining swap devices are disabled, detached all remaining storage devices are detached,  all remaining processes are killed, and your cpu is halted but the hardware is left powered on.

e)
Or if you prefer to shut down the system after a delay, without powering off the machine, you can run: shutdown  --halt  +m where +m is the delay in minuts. For instance shutdown  --halt  +10 halts the system in 10 minuts. If you want to shut down with no delay then, you can run the command shutdown  --halt  now. Option --halt is equivalent  to -H.

f) But if you want to power off your system after a delay, you should run shutdown  --poweroff  +m where +m is the delay in minuts. For instance shutdown  --poweroff  +10 powers off the system in 10 minuts. If you want to shut down with no delay then, you can run the command shutdown --poweroff  now. Option --poweroff is equivalent  to -h or -P.

g)
You can run the  systemctl reboot to reboot the system.

h) But if you want to reboot your system after a delay then,  you should run shutdown  --reboot  +m where +m is the delay in minuts. For instance shutdown  --reboot  +5 reboots the system in 5 minuts. If you want to shut down with no delay then, you can run the command shutdown --reboot now. Option --reboot is equivalent  to -r.

i)
You can specify a time string as the argument of shutdown. For instance: shutdown  -r  16:30 reboots the system at 16:30.

j) You can cancel a pending shutdown typing: shutdown  -c


2- Commands halt, poweroff and reboot

a) halt instructs the hardware to stop all CPU functions, but leaves it powered on. You can use it to get the system to a state where you can perform low level maintenance.Note that in some cases it completely shuts down the system.

b)
poweroff
instructs the system to power down, in other words, the power supply is disconnected.

c)
reboot 
instructs the system to restart.

d) halt
, poweroff, and reboot are soft links to  systemctl.

3- Suspending and hibernating the system


a) Storing a system states means:

b)
To suspend (or suspend-to-RAM)  the system, type the following command at a shell prompt as root user :

systemctl  suspend

Features of this state:
 NOTE: After suspending your system, on VirtualBox click on Machine --> ACPI Shutdown in order to wake up your system.

c) To hibernate (or suspend-to-disk)  the system, type the following command at a shell prompt as root user:

systemctl  hibernate


Features of this state:
NOTE: After hibernating your system, you have to boot again your computer, but it boots quickly and the system state is restored.

4- Additional documentation
a) https://www.kernel.org/doc/html/v4.18/admin-guide/pm/sleep-states.html
b) https://www.tecmint.com/shutdown-poweroff-halt-and-reboot-commands-in-linux/