Rebooting is the go-to option that many of us rely on whenever things begin to act weirdly on a computer. Or, it could be the practical approach when new software is installed on the system and it demands a reboot.

Linux offers the reboot command to restart or reboot a system, even over a remote connection. The command is easy to remember as the name itself is literally the function.

All the ways to reboot in Linux

Well, be it shutting down your system forcefully or cleanly and safely rebooting your system, Linux has got you covered in all these situations. It has various commands in its arsenal to cater all your rebooting needs.

Let us look at the various options of commands available with Linux.

  • reboot
  • shutdown
  • pweroff
  • halt

All the commands stated above can carry out different actions like shutting down a server, rebooting a system, or halting a system. These commands function in a similar way with some minor differences.

For the purpose of this page though, we’ll be using the reboot command only.


The Linux reboot command

reboot command fits best for your local computer as well as for the remote systems.

General syntax:

sudo reboot [options]

Note: Make sure you use ‘sudo‘ when using the reboot command. Just using the reboot command alone may not work for most users.

Options available with the reboot command

You can customize the reboot command using the following options to better suit your need to reboot your system.

OptionsDescription
-ppower off the machine
--halthalt the machine
-fforce for immediate reboot
–wtmp-onlyonly writes wtmp shutdown entry, does noit actually shutdown, or reboot the system

The -p option when used with the reboot command, will power off the machine. This option works in the same way with other commands shutdown, halt and poweroff.

The -f option forces the system for an immediate reboot. Although this is a forced reboot, it results in the clean shutdown.

The –wtmp-only option allows you to make an entry to the boot log file without actually shutting down or rebooting your system.

All these options can be used with poweroff, halt and shutdown commands as well.


Using reboot command on your system

To start using the reboot command, take a look at the following example to understand the implementation better.

Syntax:

sudo reboot

Output:

After issuing the sudo reboot command, all the users will be informed that the system is being rebooted. All the processes that are currently running on your system will be notified that the system is going down.

After the reboot command is issued, no further user-logins will be allowed by the system.

You can also use the following command to reboot your system.

/sbin/reboot

Just typing this line on your terminal will immediately reboot your system.


Using reboot command on a remote Linux system

You can reboot a remote Linux system just as easily with the reboot command. Just connect to the remote system over ssh from the terminal on your local system.

General syntax:

ssh root@[remote_server_ip] /sbin/reboot

The command can be understood in pieces. Here I have used the ssh utility to log in as a root user into the remote server. In the same command, I have specified to reboot the server using the /sbin/reboot command.

Let us understand this syntax with an example.

ssh root@142.93.217.188

I have logged in as root user on the server_ip as specified in the command.

gaurav@ubuntu:~$ ssh root@142.93.217.188 
The authenticity of host '142.93.217.188 (142.93.217.188)' can't be established.
ECDSA key fingerprint is SHA256:cXEkWjt7WHy11QRMhAa8mDmjAgE2SCKkp+xpaWAKLak.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '142.93.217.188' (ECDSA) to the list of known hosts.
root@142.93.217.188's password: 
Linux debian-s-1vcpu-1gb-blr1-01 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@debian-s-1vcpu-1gb-blr1-01:~#

After logging in remotely, use the reboot command below to restart the remote system.

sudo reboot

Output:

root@debian-s-1vcpu-1gb-blr1-01:~# suod reboot
Connection to 142.93.217.188 closed by remote host.
Connection to 142.93.217.188 closed.
gaurav@ubuntu:~$

Customizing your reboot

If you’re a system admin, you can even drop a message (with the --message option) along with the reboot command to let all users on the system know why it’s being rebooted.

Example:

sudo systemctl --message="Quarterly software maintenance drill" reboot

Here, we have used the systemctl command to start the reboot command-line utility. You can also use the service command instead of systemctl.

Sample output:

System is rebooting (Quarterly software maintenance drill)

You can see the similar output in the boot logs.


Checking reboot logs

The system reboot log is stored in /var/log/wtmp file on your Linux machine. But instead of scrolling through that file, you can simply use the last reboot command to quickly check your reboot log.

last reboot | less

Sample output:

reboot   system boot  4.15.0-112-gener Tue Sep 29 16:30   still running
reboot   system boot  4.15.0-112-gener Tue Sep 29 13:21 - 16:30  (03:09)
reboot   system boot  4.15.0-112-gener Tue Sep 29 12:07 - 13:21  (01:13)
reboot   system boot  4.15.0-112-gener Tue Sep 29 08:51 - 12:06  (03:15)
reboot   system boot  4.15.0-112-gener Mon Sep 28 20:22 - 21:00  (00:37)
reboot   system boot  4.15.0-112-gener Mon Sep 28 16:27 - 16:45  (00:17)
reboot   system boot  4.15.0-112-gener Mon Sep 28 11:22 - 14:16  (02:54)
reboot   system boot  4.15.0-112-gener Sun Sep 27 23:04 - 00:22  (01:18)
reboot   system boot  4.15.0-112-gener Sun Sep 27 11:25 - 12:29  (01:03)
reboot   system boot  4.15.0-112-gener Sat Sep 26 09:52 - 12:15  (02:23)
reboot   system boot  4.15.0-112-gener Fri Sep 25 11:12 - 12:15 (1+01:03)
reboot   system boot  4.15.0-112-gener Thu Sep 24 11:13 - 17:19  (06:06)

Conclusion

Now we have a clear idea about how the Linux reboot command functions. We can safely say that most of the options that apply to the reboot command also work with the shutdown, halt and poweroff command. We can now easily use the reboot command to swiftly reboot your Linux system.