Reboot system boot in linux

How to boot, shut down, and suspend your system from the Linux command line

Learn how to schedule timed shutdowns and reboots with systemd and to hibernate your system with systemctl.

Sysadmin working on three monitors in dark room

Let’s face it: The most fundamental thing we do with computers is turn them on and off. Everything else happens between those two particular events. And sometimes, restarting the system is a key component of troubleshooting or completing installation processes.

Training & certification

Typically, you need root privileges to shut down or reboot the system. Ensure your account is configured in /etc/sudoers for this authority. Remember, it’s generally a bad idea to log on directly as root.

Boot the system

Starting the system is as simple as pressing the power button. What happens from there varies a bit depending on your hardware, but in general, the process looks like this:

  1. The firmware (BIOS or UEFI) finds the boot media.
  2. The boot loader starts, and the Master Boot Record (MBR) or GUID Partition Table (GPT) loads.
  3. The operating system selection menu appears.
  4. The boot loader stage 2 starts and loads the selected kernel.
  5. The kernel and drivers load and mount the root filesystem.
  6. systemd launches as PID 1.
  7. The default.target file loads.
  8. The user is prompted to authenticate.

The system launches to the default.target (providing either a command-line interface or graphical environment). Changing these targets is outside the scope of this article but is something I cover in How to switch between the CLI and GUI on a Linux server.

Shut down the system

When Red Hat Enterprise Linux (RHEL) adopted systemd with RHEL 7, what happened to the venerable Linux shutdown command? It remains—but now it maps to systemd’s shutdown functions.

The shutdown command features two options: —halt and —poweroff . The —halt option stops the operating system while the —poweroff option turns off the system.

One of the main benefits of the shutdown command is the ability to define a shutdown delay to give users time to save their work and log off the system. Schedule a time that suits your needs by using the format hh:mm (24-hour time designations).

For example, to halt the system at 10pm, type:

It’s more likely that you’ll want to halt the operating system a few minutes into the future. In that case, specify the number of minutes from now to begin the shutdown process.

For example, to halt the system after a five-minute delay, type:

You can append a message to all users by entering it after the time specification, like this:

$ sudo shutdown --halt +5 “Attention. The system is going down in five minutes.”

Cancel a timed shutdown by using the -c option:

Читайте также:  Linux не резолвит адреса

IT Automation ebook

You can also use the systemctl command to shut down the system. For example, type systemctl halt or systemctl poweroff to achieve similar results to the shutdown command. The main disadvantage of using systemctl is losing the ability to schedule or cancel the shutdown process.

Reboot the system

When someone approaches you for help with their computer, I suspect one of your first responses is, «Did you reboot it?» Restarting a computer helps with various problems and may even be necessary to finalize some configurations. However, restarting is considered downtime on a server and should be avoided if possible. Try to use systemctl restart to restart services rather than reboot the whole system.

However, sometimes a restart is inevitable. The option for restarting the system immediately with the shutdown command is -r , so it looks like this:

You can still specify a delayed time using the hh:mm format explained above.

You can also use systemctl to reboot the device by typing:

Again, the disadvantage with systemctl is the inability to delay the process.

Suspend the system

Great Linux resources

There are a couple of ways to place the system in a reduced or no-power mode. The first is suspend and the second is hibernate.

When you suspend the system:

  • Contents of memory are moved to the swap location.
  • The boot loader is configured to boot directly to the current kernel.
  • The system shuts down (no-power mode).
  • Upon power up, the system reloads itself from swap.

When you hibernate the system:

  • Applications are stopped.
  • System state is moved to RAM.
  • The system remains powered on in a low-power state.

You can also suspend and hibernate the system by using the systemctl command. The commands are exactly what you’d expect:

$ sudo systemctl suspend $ sudo systemctl hibernate $ sudo systemctl hybrid-sleep

The systemctl hybrid-sleep command both suspends and hibernates the system.

Use the GUI

Depending on the graphical user interface (GUI) environment you have installed, you can initiate a reboot or shutdown from a menu. Many people rely on a graphical desktop like GNOME, so this is certainly a viable option.

Power off and log out options in GNOME

[ Because sudo is something you don’t configure often, it can be hard to remember its nuances. Download the Linux sudo cheat sheet. ]

Wrap up

The familiar shutdown command now maps to systemd and executes timed shutdowns and reboots. You can use systemctl if you wish, but being able to schedule the shutdown is helpful. In addition, systemctl also offers suspend and hibernate options. Try to avoid bringing down the system when possible, but sometimes it’s necessary.

Источник

What is the Linux Reboot Command?

What is the Linux Reboot Command?

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.

Читайте также:  Open project for linux

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.

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:

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.

Options Description
-p power off the machine
—halt halt the machine
-f force for immediate reboot
–wtmp-only only 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.

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.

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.

Читайте также:  Нужно ли обновлять linux mint

Let us understand this syntax with an example.

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.

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.

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 reboo t command to quickly check your reboot log.

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.

Источник

Оцените статью
Adblock
detector