reboot command in Linux with Examples
reboot command is used restart or reboot the system. In a Linux system administration, there comes a need to restart the server after the completion of some network and other major updates. It can be of software or hardware that are being carried on the server. The reboot is needed so that the changes that the user have done can be affected on the server. For example, if the user is re-compiling the server’s kernel that is going through some more advanced server administration, then he needs to restart the machine in order to complete the compilation and to have a new updated kernel version on the server. When Updating the server’s memory, IP allocation, NIC configuration are the key tasks that need to be done on the server restarted once leading to their successful implementation. Most of the Linux system administrators access their servers via shell or SSH to perform a bunch of administrative activities, server management, and monitoring. So they need to know the basic commands to restart the server from the shell.
- –help : This option prints a short help text and exit.
- –halt : This option halt the machine, regardless of which one of the three commands is invoked.
- -p, –poweroff : This option will going to power-off the machine, regardless of which one of the three commands is being invoked.
- –reboot : This option reboot the machine, regardless of which one of the three commands is invoked.
- -f, –force : This option force immediate halt, power-off, or reboot. When it is specified once, this results in the immediate but clean shutdown by the system manager. When it is specified twice, this results in immediate shutdown without contacting the system manager. See the description of the option –force in systemctl(1) for more details.
- -w, –wtmp-only : This option only writes wtmp shutdown entry, it do not actually halt, power-off, reboot.
Restart your system: If you just need is a restart without going into any details just help yourself by using any one of the following commands:
$sudo shutdown –r now
Note that the usage of the reboot, halt and poweroff is almost similar in syntax and effect. Run each of these commands with –help to see the details.
Scheduled a Restart: Simple reboot command has limited usage. The shutdown command is being used instead of reboot command to fulfill much more advance reboot and shutdown requirements. One of those situations is a scheduled restart. Following is the syntax which is being used to reboot your system after time defines by the TIME.
$sudo shutdown –r [TIME] [MESSAGE]
Here the TIME has various formats. The simplest one is “now”, already been listed in the previous section, and tells the system to restart immediately. Other valid formats we have are +m, where m is the number of minutes we need to wait until restart and HH:MM which specifies the TIME in a 24hr clock. Below are the examples and their respective outputs. Optional MESSAGE argument can be used to intimate the users prior to reboot to prevent the possible loss of data.
Command to reboot your system after 5 minutes:
$sudo shutdown –r +5
Reboot your system after 02:00 A.M :
$sudo shutdown –r 02:00
Cancelling Restart: If you want your system to discard the previously scheduled restart or shutdown you can simply call another shutdown command with the –c option and broadcast with it a message for the users about the cancellation of the restart.
$sudo shutdown –c [MESSAGE]
Cancel your scheduled Reboot: The previously scheduled reboot can be canceled by the system administrator by simply issuing another shutdown command with the –c option and an optional message argument.
$sudo shutdown -c "our custom example of canceling a scheduled shutdown"
Restarting remotely your server: Simply login your server with any of the ssh client using server authentication information and simply issue any of the following commands:
$ ssh email@example.com /sbin/reboot
$ ssh firstname.lastname@example.org /sbin/shutdown –r now
Restart with the Init Command: Init is actually taken from the word initialize that is widely been used to initialize/start different processes in a Linux machine, so this command used as a joint with the runlevel 6; a number which is been set for rebooting a Linux server leads to getting the server rebooted. The syntax for this is mentioned below:
[root@test ~]# init 6
[root@test ~]# /sbin/init 6
Checking your reboot logs: /var/log/wtmp is the file records in which all logins and logouts records are kept. One can parse this file with the last command in order to access log for the reboot. Below you can find the last command usage and its output on my system.