There are some situations where you need to restart your system. If you are using a GUI-based Linux system then you can restart it by clicking on the Power Off and then Restart button as given in the image below.
But how would you reboot a Linux server or a system that doesn’t have a graphical user interface? Well, Linux comes with some command-line utilities for example systemctl, to do this task.
In this article, I will explain how to restart or reboot a Linux system from GUI and the command line.
When should you restart your system?
You should reboot your system in circumstances like –
- If your computer is running slow or acting “weird”
- Unexpected system freeze-ups
- Temporary driver or hardware error
- Internet connectivity issues
- After a software or patch update unless you’re using Livepatch
- After a software or hardware installation
Prerequisites
To restart a Linux system you must be logged in as a root or user with sudo privileges.
How to restart your Linux system
Restarting a system flushes random access memory as a result you get improved system performance. There are different ways using which you can restart your system.
By using the systemctl command
Open your terminal and execute the given command –
sudo reboot
OR use –
sudo systemctl reboot
You can reboot a system by sending a message explaining the reason why we are going to reboot the system.
sudo systemctl --message="Linux kernel upgrade" reboot
The following message will be displayed in the log –
System is rebooting (Linux kernel upgrade)
By using the shutdown command
The shutdown
command is a safe way to power off or reboot your system, allowing disks to sync and processes to end.
You can use the option -r
with shutdown
command to reboot your system.
sudo shutdown -r now
To reboot after a certain time use the given command –
sudo shutdown -r 10
This will reboot your system after 10 minutes.
By using telinit command
A runlevel is the state of the init process that is used by the system to determine in which mode it has to operate. It implements the style of initialization in Unix System V. Generally, there are seven runlevels i.e. from runlevel 0 to 6.
Different distributions can assign each state uniquely. The description of the standard runlevels is given below –
0 – Halt
1 – Single-user mode
2 – Multi-user mode with no NFS
3– Multi-user networking mode(command line)
4-undefined
5-Multi-user mode (GUI)
6– reboot
The telinit command is a frontend to your init system, in systems that use systemd it links to the systemctl command. This command takes a single character as the argument.
We can reboot a system by sending it to runlevel 6 from the current state. To reboot your system using telinit command use –
sudo telinit 6
Similarly, you can use the following command to power off your system –
sudo telinit 0
How to restart a remote server
To reboot your remote server first you need to connect to it by using ssh or an ssh client like putty. Use the given command to connect to the remote system-
ssh –t user_name@server_ip_OR_hostname
Once get connected you can use one of the commands that are given in the above section.
OR use the following command –
ssh –t user_name@server_ip_OR_hostname ‘sudo reboot’
This will reboot the remote server immediately.
For example –
ssh lalit@192.168.122.175 'sudo reboot'
Conclusion
If you are working with a command-based system you should know the command to restart it. Now if you have a query then write us in the comments below.