Linux is one of the versatile operating systems. It provides various terminal line commands to carry out several tasks. One of those simple tasks is to reboot Linux, shutdown, or restart the Linux system via a command-line interface. If you are a Linux administrator, you might come across rebooting or restarting the system much time or during significant updates. Sometimes a reboot is necessary so that everyone can affect the changes on the server.
For example, suppose you are recompiling the system’s kernel under any significant change. You need to restart the system for compilation and update the new kernel version on the server/system. There are other important tasks that require the system to be rebooted/restarted, such as updating the server’s memory, allocating IP, configuring NIC, etc. Most jobs are managed by giving commands via shell or SSH, so the administrators must know the basic commands to reboot or restart the system.
This article has mentioned some commonly used command-line interface commands for rebooting or restarting the Linux system.
The syntax for the Linux Reboot command
It is one of the other simple commands triggered from the command-line interface. It has a straightforward syntax and various options for various functionalities, as shown below.
reboot [OPTIONS...]
Available Options:
- –help: prints a short text regarding the command and exit.
- –halt: halts the machine, irrespective of the following three commands are invoked.
- -p, –poweroff: power off the system no matter which command is in process.
- –reboot: reboot the machine no matter which command is running.
- -f, –force: it ensures the forced halt of the system, power-off, or reboot. If you mention this option once, it results in the system manager’s clean shutdown. But, if mentioned twice, it will immediately shut down the system without contacting the system manager.
- -w, –wtmp-only: it will only write the shutdown entry.
Examples
-
Starting your system
Without getting into details, you can restart your system by executing any following commands.
$sudo reboot
$sudo shutdown –r now
-
Scheduling a restart
If you run the simple reboot command, as shown above, it will simply reboot it with any other function. You can use the shutdown command for a more advanced reboot option, such as scheduling a restart as per your requirement (Ubuntu restart command).
If you want to schedule a restart or reboot after a definite time, you can execute the following Linux restart command at a specified TIME.
$sudo shutdown –r [TIME] [MESSAGE]
You can specify TIME in various formats. One of the values for TIME is “now” that we have mentioned in the above example, which immediately restarts the system.
Other formats are
- +m specifying the minutes to wait until the next restart.
- HH:MM specifies the TIME in the form of 24hr clock.
- Optional MESSAGE argument intimates the users before reboot to prevent data loss.
Example-
- If you want to reboot your system after 5 minutes, run the following command.
$sudo shutdown –r +5
- If you want to schedule your system’s reboot after 02:00 A.M, you can hit the following command.
$sudo shutdown –r 02:00
-
Cancelling the scheduled restart
You have the right to discard the already scheduled restart or a shutdown by running the
shutdown command along with the “-c” option. You can also specify a message to all the users about the cancellation of the restart.
$sudo shutdown –c [MESSAGE]
Here, [MESSAGE] will be the text sent to all users.
-
Cancelling your scheduled reboot.
If you are a system administrator, you are authorized to cancel the scheduled reboot of the system. For this, you need to execute the following shutdown command with the “-c” option and an optional message, as shown below.
$sudo shutdown -c “cancelling a scheduled shutdown.”
-
Restart your server remotely.
To restart your server remotely, you first need to log in using the ssh command and appropriate credentials. Once you are in, you can execute the following commands.
$ ssh [email protected] /sbin/reboot
$ ssh [email protected] /sbin/shutdown –r now
-
Restarting with Init.
Here Init stands for initialization specifying the initialization of various processes within the system. You can use the init command along with the number 6. Here the number 6 has already been set for the reboot of the Linux system or servers.
sudo init 6
OR
sudo /sbin/init 6
-
Checking the reboot logs.
Linux system has a set location where all the logins and records are stored- /var/log/wtmp. You can access the content of this file by executing the last command. Below, you can find my system’s last command usage and output.
$last reboot
Conclusion
Reboot is a common task required for every system for proper function or changes that affect the system. Various commands are available that are helpful for this purpose, even with advanced options like scheduling the reboot Linux. Such functionalities are useful when you want to reboot the system at the off time.
We have mentioned all the commands for reboot and shutdown of the Linux system with different arguments. Try these simple commands yourself.
If you're looking to host a website or run complex applications, buy linux vps hosting can provide you with the power, flexibility, and security you need to meet your goals
People also read: