Red Hat Certified System Administrator(RHCSA)

Operate Running Systems

Boot reboot and shutdown a system safely

In this guide, you'll learn how to safely boot, reboot, and shut down Linux systems using appropriate commands. These best practices ensure that your system management tasks are executed correctly and securely.

Using systemctl for Rebooting and Shutting Down

To reboot or shut down your Linux machine, the recommended approach is to use the systemctl utility. Note that some of these commands require administrator privileges, which the root user has by default.

For example, to reboot the system as the root user, enter:

systemctl reboot

If you are logged in as a regular user, you need to prefix the command with sudo to temporarily gain root privileges:

sudo systemctl reboot

You'll see a prompt similar to the following when using sudo:

[sudo] password for aaron:

Remember, if you're logged in as root, executing these commands without sudo is acceptable.

The same method applies to shutting down your system. For a regular user, use:

sudo systemctl poweroff

Managing Abnormal Situations

Occasionally, a system may refuse to reboot or shut down normally because an application is misbehaving or unresponsive. In these cases, you can force the command. However, exercise caution and use this option only as a last resort.

Force Reboot:
To force a system reboot, append the --force (or --f) option:

sudo systemctl reboot --force

Force Shutdown:
Similarly, to force a power-off, include the --force option with the poweroff command. As an extreme measure, using the force option twice will immediately reboot or power off the system—akin to pressing the reset button or unplugging the machine. This abrupt approach does not allow applications to close properly or save data.

Warning

Using the force option can result in data loss or system instability as it bypasses the regular shutdown processes. Use it only when absolutely necessary.

Scheduling Reboots and Shutdowns

Manually rebooting a server during inconvenient hours, such as the middle of the night, can be challenging. Linux offers the ability to schedule reboots or shutdowns with the shutdown command, allowing you to set a specific time or delay.

Specifying a Time to Shut Down or Reboot

To shut down the system at a specific time (using the 24-hour format), run the following command. For example, to shut down at 02:00:

sudo shutdown 02:00

You can also schedule a shutdown after a certain number of minutes by using the +x format. For example, to shut down after 15 minutes:

sudo shutdown +15

To schedule a reboot instead, add the -r option. For instance, to reboot at 02:00:

sudo shutdown -r 02:00

Or to reboot after 15 minutes:

sudo shutdown -r +15

Announcing a Scheduled Shutdown or Reboot

If multiple users are logged into the system, you can broadcast a notification about the upcoming shutdown or reboot. This message gives everyone a chance to wrap up their tasks before the system goes offline. To include a message, enclose it in single quotes:

sudo shutdown -r +1 'Scheduled restart to do an offline backup of our database'

The above message will be displayed to all logged-in users.


That's the end of this guide. By following these best practices and commands, you can safely manage system reboots and shutdowns on Linux. Stay tuned for more best practices and additional commands related to system maintenance and administration.

For further reading, consider checking out these resources:

Watch Video

Watch video content

Previous
Process script inputs 1 2 etc