Introduction to Linux Reboot Command
Reboot command in Linux is a way to restart a system from its existing state. It might sound cliché, but it is a widely known quote that reboot solves primal problems. And many would have felt this the way it is quoted as well. Now, this is only a quote as there is also a scientific or one can say software-based logical explanation to the same. After Reboot, the system helps in purging the software which is malfunctioning from its active memory, and after it has rebooted, loads the software as a clean copy on the active memory. Not only this, it is often times required to refresh the system with the latest configuration changes and updates in the process of the operating system and that is also a place where reboot comes in very handy!
Syntax of Linux Reboot Command
There are multiple ways of executing a reboot command. Some of the commands will involve the keyword reboot and some of them might not contain the keyword. The ones which do not contain the keyword also perform exactly the same way as expected from a reboot command.
This syntax is the simplest of all, where just incorporating the keyword will help in accomplishing the required action. In this syntax, there is multiple options present which we will talk about in the later part of the course.
sudo shutdown –r
Though this command portrays another keyword, it exactly does the requirement asked for in a reboot command. Here, the shutdown is the keyword Linux looks for while this command gets executed. With -r as an option, it sends a signal that this command should execute reboot as reboot requires shutting down and then power on its own and doesn’t require a manual intervention to start.
init is a keyword which means initializing and it’s used for initializing or starting a process on the system. This command comes in very handy for those who are experts in working with Linux and have a good sense of the option init provides. This command invokes a runlevel 6 which is reserved for restarting a Linux
How does Reboot Command work in Linux?
Now that we have a fair idea on what reboot command looks like, what the syntax is, it becomes even important on understanding what the use cases of reboot command would be, the working of reboot command, and many such options available for using the reboot command.
As an admin, we would always want to keep our Linux system up to date, and with any major updates related to either network or security patching, restarting of the Linux system is inevitable. In some cases, these updates can be carried on the server and for these changes to be reflected across all users, the admin needs to restart the Linux system.
In a normal reboot, what we do is shutting down the operating system, but using reboot command what we do as an alternative is allowing the firmware for overtaking the system to restart itself. One tends to confuse rebooting with hard rest, but the subtle difference is hard to rest is nothing but forcibly shutting down the system, whereas rebooting is a normal process that includes controlled shutdown!
Below are the few steps which are followed in rebooting:
- A HUP signal is sent to all the users using the Linux system about the potential restart or reboot that is expected to happen. In simple words, HUP is a kind of notification signal which gets launched when the corresponding controlling terminal is closed.
- A controlled process is followed for shutting down all services, for example, any process which are dependent on the closing of other processes is later in the priority of closing so that there is no technical glitch when the system reboots.
- In case there are some sessions, which are not shutting down due to some reason, the TERM signal is sent and if not responded within the stipulated time, a KILL command is sent.
- Now, any filesystems that are network based are unmounted so that all cached write operations are completed before unmounting.
- Next, any services which accesses network filesystems are shut down, and just next to that any write operations to local disks are allowed to be completed.
- Finally, after all, these are done, a hardware signal is sent to the kernel letting it know to reboot the system!
In the next section, we will look at different options to understand which all steps are deemed fit in which of the options.
Reboot Command Options
In Linux, reboot command has the following options:
- –help: This allows the user to look at the documentation related to the reboot command. This commands just prints the different options available with reboot and exits.
- -p or –poweroff: This option will enable the system to power off only i.e. power down
- -f or –force: This option will impose all the required actions forcefully. In case this option is used, there is no clean shutdown that takes place. In short, all the steps in our last section are skipped except for the last one.
- -w or –wtmp-only: When this option is chosen, only wtmp shutdown entry is recorded without any halt/power-off/reboot
In order to have a scheduled shutdown we would need to take help of the command shutdown and the syntax goes as:
shutdown –r [TIME] [MESSAGE]
sudo shutdown -r 02:00
sudo shutdown -r +5
sudo shutdown -r 00:00 “Server has some new updates and hence will shutdown”
Here, the [TIME] if mentioned in HH:MM, will be taken as the time of the day in 24-hour format, and if it is of the formal +<integer>, it is assumed to be a number of minutes the system will wait before initiating the reboot.
In this article we have gone through the usage of reboot command in real life through a series of examples and also looked into different options that are available for the developers to use. This capability when used by admin makes the restart of the system super smooth and timely so that all necessary actions are planned before the system shuts down.
This is a guide to Linux Reboot Command. Here we also discuss the introduction and syntax of linux reboot command along with how does it work. You may also have a look at the following articles to learn more –