Linux Foundation Certified System Administrator (LFCS)

Operations Deployment

Boot Reboot and Shutdown a System Safely

In this lesson, you will learn several methods to boot, reboot, and shut down a Linux system safely using system commands. Linux uses the systemctl command (short for "system control") to manage system states, and many of these commands require administrative privileges. The root account inherently has these privileges; however, regular users can execute them by prefixing commands with sudo.

Root vs. Sudo

If you are logged in as root, you do not need the sudo prefix for any of these commands.

Below, we present a summary of the fundamental commands for rebooting and shutting down your system.

Rebooting the System

As the Root User

When you are logged in as the root user, simply execute:

$ systemctl reboot

As a Regular User with Elevated Privileges

If you are a regular user, use sudo to obtain temporary root privileges:

$ sudo systemctl reboot
[sudo] password for aaron:

Summary of Reboot Commands

# When logged in as root:
$ systemctl reboot

# When using sudo as a regular user:
$ sudo systemctl reboot
[sudo] password for aaron:

Shutting Down the System

To safely shut down the system, whether as root or using sudo, execute:

$ sudo systemctl power off
[sudo] password for aaron:

In certain cases, an unresponsive or misbehaving program may cause the system to refuse a normal reboot or shutdown. In such instances, you can force the operation by appending the --force flag. Use this option only when absolutely necessary.

$ sudo systemctl reboot --force

or

$ sudo systemctl power off --force

If a single force does not succeed, you may specify the force flag twice. This method functions similar to pressing the physical reset button, immediately rebooting the system without allowing programs to close properly or save their data.

Caution

Forcing a reboot or shutdown can result in data loss. Use the force option only as a last resort.

Scheduling Reboots and Shutdowns

In managed server environments, you might need to perform scheduled reboots or shutdowns without manual intervention, often during off-peak hours. The shutdown command is ideal for this purpose.

Schedule a Shutdown at a Specific Time

Use the 24-hour format when specifying a shutdown time:

$ sudo shutdown 02:00
[sudo] password for aaron:

Schedule a Shutdown after a Delay

To schedule a shutdown a certain number of minutes in the future, replace the time with a plus sign (+) followed by the delay in minutes. For example, to shut down after 15 minutes:

$ sudo shutdown +15
[sudo] password for aaron:

Schedule a Reboot

To schedule a reboot, simply include the -r option. For instance:

# Schedule a reboot at 2 a.m.
$ sudo shutdown -r 02:00
[sudo] password for aaron:

# Schedule a reboot after 15 minutes
$ sudo shutdown -r +15
[sudo] password for aaron:

Utilizing the Wall Message Feature

The shutdown command supports a wall message feature that notifies all logged-in users about an impending reboot or shutdown. This feature gives users time to save their work or prepare for disconnection.

For example, to schedule a reboot in one minute while displaying a message about a scheduled Linux kernel upgrade, use:

$ sudo shutdown -r +1 'Scheduled restart to upgrade our Linux kernel'
[sudo] password for aaron:

Conclusion

By following these system commands and scheduling techniques, you can manage the boot, reboot, and shutdown processes of a Linux system safely and efficiently. Make sure to use forced options only when absolutely necessary to prevent potential data loss, and always provide clear notifications to your users when scheduling system maintenance.

For additional Linux administration tips, please refer to the official Linux documentation.

Watch Video

Watch video content

Previous
Git Branches and Remote Repositories