Linux reboot / shutdown command
Linux, like all duties, stop and restart operations can also be done from the command line. Orders are shutdown, halt, poweroff, and reboot REISUB strikes.
In this post I’ll show you how to stop or restart a Linux system using these commands. The controls are most useful when you need to reboot a linux server remotely, where the shell access is available and no GUI. Servers often require a reboot upgrades are installed or need to stop other tasks Maintenance.
Commands are available on a Linux system like Ubuntu, CentOS, Debian, Fedora or SUSE and do not require installation of any additional packages.
The first command is the shutdown command and it can be used to shutdown a system or restart it. It is commonly used to shutdown or reboot both local and remote machines.
shutdown arranges for the system to be brought down in a safe way. All logged-in users are notified that the system is going down and, within the last five minutes of TIME, new logins are prevented.
The syntax is
shutdown [OPTION] [TIME] [MESSAGE]
To shutdown a machine call the shutdown command like this
# shutdown -h now
The h option is for halt which means to stop. The second parameter is the time parameter. “now” means that shutdown the system right away.
The time parameter can be specified in minutes or hours also. For example
# shutdown -h +5 "Server is going down for upgrade. Please save your work."
The above command shall flash the message to all other logged in users and give them 5 minutes before the system goes for shutdown.
The shutdown command can be used to restart a system with the r option instead of the h option. Usage is same as before. Just replace the h option with r option.
# shutdown -r +5 "Server will restart in 5 minutes. Please save your work."
All other logged in users will see a broadcast message in their terminal like this
[root@dhcppc1 ~]# Broadcast message from root@dhcppc1 (/dev/tty1) at 21:35 ... The system is going down for reboot in 5 minutes! Server will restart in 5 minutes. Please save your work.
At this point a shutdown can be cancelled by calling shutdown with “c” option.
# shutdown -c
Next command is the reboot command. It can be used to shutdown or reboot linux.
The following command will shutdown linux.
# reboot -p
The “p” options stands for poweroff.
To reboot linux just call the reboot command directly without any options.
This will perform a graceful shutdown and restart of the machine. This is what happens when you click restart from your menu.
Reboot linux forcibly
The following command will forcefully reboot the machine. This is similar to pressing the power button of the CPU. No shutdown takes place. The system will reset instantly.
# reboot -f
The man page explains it as follows
When called with --force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself (with REBOOTCOMMAND argument passed) and directly reboots the system. Otherwise this simply invokes the shutdown(8) tool with the appropriate arguments without passing REBOOTCOMMAND argument.
3. halt command
The next command is the halt command. This can shutdown a system
The halt command also has a force option, but you do not want to use it. It is supposed to shutdown the system instantly. But its behaviour may not be consistent. Desktops might hang on running this command.
4. poweroff command
There is another command exactly same as the halt command. It does the same things and takes the same options.
REISUB – R E I S U B key strokes
The commands listed above can be used when you are in control of your system. What if the system is hung and does not respond at all. And you do not want to press the power button on the CPU that could lead to data corruption. To save from such a situation is the magic SysRq keys.
A special combination of keys that will help you reboot your Linux system, no matter how it is hung. See the Wikipedia article. for more information.
A common use for the key to magic is to perform a safe restart a Linux computer that was also blocked. This can prevent a fsck being required to restart and gives some programs a chance to save emergency backups of unsaved work.
Note: By pressing the following keys would instantly restart your system. Its similar to press the power button on your CPU or execute the reboot command.
ALT + PrintScreen + B
Now in place of the B key we have to use R E I S U letters first. Each key does a task as mentioned below
unRaw (take control of keyboard back from X), tErminate (send SIGTERM to all processes, allowing them to terminate gracefully), kIll (send SIGKILL to all processes, forcing them to terminate immediately), Sync (flush data to disk), Unmount (remount all filesystems read-only), reBoot.
1. Hold down the Alt and SysRq (Print Screen) keys.
2. While holding those down, type the following keys in order, several seconds apart: R E I S U B
3. Computer should reboot.
Make sure to have some time gap between each of keys R E I S U B.
The sysrq feature can be controlled by changing the value of /proc/sys/kernel/sysrq. To check if sysrq is enabled on the system or not, echo the value. It should be non zero.
$ cat /proc/sys/kernel/sysrq 176