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

Practical Exercise 10b: Basic power management

GENERAL CONDITIONS
a) You do not have to send any report but questions about this exercise could be asked in the 2n and final exams.
b) You should know how to work with the commands systemctl, shutdown, halt, poweroff, reboot
c) You should know the meaning of the poweroff and halt the system.
d)
You should know the meaning of hibernating and suspending a system

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 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, and your cpu is halted but the hardware is left powered on.

e)
Or if you prefer to shut down and halt he system after a delay, 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) If you want to power off your system, you can systemctl  poweroff. If you run this command, the power supply is disconnected.

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. Reboot = shutdown + boot again.

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.

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/