How to reboot ubuntu through the command line

How to Reboot Ubuntu through the Command Line

Although Linux does not require frequently restarting as opposed to Windows, sometimes major system updates or serious system glitches may require a system restart. With the introduction of ‘kptach’ by RedHat, system administrators can easily patch critical security updates to the Linux kernel. There is no need to look for the processes to complete, log off the system, or crontab any reboot task. It also increases system uptime without losing productivity. ‘Livepatch’ by Ubuntu also works in the same way. With Livepatch, vulnerability fixes can be patched on the Ubuntu Linux Kernels.

Reboot process helps deadlocked programs exit, apply critical patches, remove temporary files, repair damaged file systems, and perform many system management tasks.

What
Sponsored
will we cover?

In this guide, we will see different ways of rebooting a Linux Ubuntu 20.04 machine from the command line and GUI. Let’s get started with this tutorial.

Using the Shutdown command

This command can be used to stop, power off or restart a machine. It uses a time argument to specify the time for execution. The time argument is ‘now’ for triggering immediate operation. For example, to immediately reboot a system use the ‘-r’ flag with the ‘now’ string:

$ sudo shutdown -r now

In the same way, if you want to schedule a reboot after 5 minutes, use the below command:

$ sudo shutdown -r 5

The time format is “hh:mm” in 24-hr clock format. We can also use ‘+m’ to reboot after ‘m’ minutes from now.

It should be noticed that the ‘shutdown’ command itself also has the capability to shut down, reboot, stop and power off a system.

Using the Reboot command

From the terminal perspective, the reboot command is the fastest and easiest way to reboot a system. Simply type the below command to reboot:

$ reboot

In fact, it is a shortcut for the ‘shutdown -r now’.

Using ‘Init’ the command

In linux, ‘/sbin/init’ is the first process that executes once the kernel is loaded. It means the process has PID 1.

In Linux systems that do not have ‘systemd’, the ‘init’ command stops all running processes, and the disks are then synchronized prior to switching the init states or run levels. The run level 5 is the default run level. The ‘init 6’ command halts the running system and restarts the system to a state listed in ‘/etc/inittab’. To restart, simply use:

$ sudo init 6

In case we want to reboot the Linux Ubuntu to a multiuser state, use the command:

$ sudo init 2

Similarly, to reboot to a Single-User State (Runlevel S), use the command:

$ sudo init s

To reboot to single user mode is to use the command:

See also  How to develop Linux applications for FIPS on Ubuntu
$ sudo /sbin/init 1

To check your current run level, run the following command:

Sponsored
$ runlevel

If the output is like ‘N  1’, this means we have no old runlevel as we have just booted the system:

How to reboot ubuntu through the command line 1

Now let us boot to runlevel 1 (also called runlevel s) and check the runlevel status:

How to reboot ubuntu through the command line 2
As you can see, the status has now changed to ‘5 1’. We can again switch back to runlevel 5 by running:

$ sudo /sbin/init 5

The ‘SYSTEMD’ Way

‘Systemd’ has replaced the init process, so the ‘/sbin/init’ has now become a symbolic link to systemd.

On systems having systemd ( as opposed to the init system), you may not find ‘/etc/inittab’. In such a case, use the below command to reboot a system:

$ sudo systemctl reboot

Just like runlevels in the SysV init system, systemd uses the so-called “target” system. The above ‘systemctl’ command is the primary interface to systemd. The runlevel 6 of the SysV init system has its equivalent target in systemd as “reboot.target”. So you can also use the above reboot command as:

$ sudo systemctl isolate rescue.target

The Restart Button

The simplest and quickest solution is, of course, the reboot button. When you click on the right top corner of your Ubuntu 20.04 system, you will find the ‘Power Off / log Out’ option.

How to reboot ubuntu through the command line 3

Now when you click on this option, you will see the last option as ‘Power Off’. Press this label, and it will bring you the Power Off window. Hit on the ‘Restart’ button to reboot the system.

How to reboot ubuntu through the command line 4
You can also find this window by typing ‘reboot’ in the Gnome search bar:

How to reboot ubuntu through the command line 5
Another way is to use the physical power button; this will display the Power Off window. But beware, this may require first configuring the power button behavior from inside the system settings.

Conclusion

In this guide, we have learned about different ways of rebooting a Ubuntu machine. This guide can also be used for many other Linux distributions besides Ubuntu since all commands are generally the same for them. We have not provided many screenshots of the practicals because it’s not possible to snap a reboot process. But we are sure this guide will run smoothly for your system.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply