- How to properly shutdown or reboot a Unix/Linux server
- 6 Answers 6
- How to Reboot and Shutdown Linux Servers?
- GUI Method
- systemctl Command
- shutdown Command
- Reboot Command
- Halt Command
- Poweroff Command
- init Command
- Power Button
- Alt + SysRq Combination
- Summary
- How to use Linux Shutdown Command with Examples
- shutdown Command Syntax
- How to Use the shutdown Command
- Shutdown With All Parameters
- How to Shut Down the System at a Specific Time
- How to Shut Down the System Immediately
- How to Broadcast a Custom Message
- How to Cancel a Scheduled Shutdown
How to properly shutdown or reboot a Unix/Linux server
What is the correct way to turn off a Unix/Linux server? From my googling, I have learned (hopefully) the following: shutdown: I should use this, with the parameter -h to halt, or the parameter -r to reboot halt: halts the computer (stops the processor? does this physically turn the power of the computer off?). I think this will call shutdown if not at init0, otherwise just halts. reboot: if not at init6, calls shutdown, otherwise just reboots the computer. if all that is correct, then the only thing I can’t figure out is what exactly ‘halt’ does. Does it just stop the processor but not turn the computer physically off? How do I «poweroff» the computer? Thanks
6 Answers 6
shutdown -h now will shut off the computer with most systems, but it is left up to the implementation. Use -P to poweroff for sure and -H to halt for sure. This is the method I would recommend to shut the system down. It will run all the proper scripts.
halt without -f will just call the above shutdown and so will reboot , they are basically just aliases.
Thoreau makes another good point: you should try to make a habit of calling important system commands with an explicit path, ( e.g. /sbin/shutdown ). This might save you if your system is ever compromised and you are not aware of it.
mystikphish: Agreed, going to adopt that habit. Although he has a good point, I don’t know if I would trust his advice on IT in general if he spends all his time in a one room cabin with no electricity.
It would be a poor compromise if it didn’t change the executable in the path that is engrained in your fingers though.
How to Reboot and Shutdown Linux Servers?
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.
As a Sysadmin, one of the frequent activities is to reboot or power off servers.
This could be due to regular maintenance activity like OS patching or due to some hardware failure that requires a system to be powered down for maintenance.
A Linux system offers several different ways to reboot or shut down the server. A normal system should respond to any command while a degraded server may need to be rebooted forcefully. Do note that most of these commands will require a certain level of privilege either as superuser or with sudo to be executed successfully since rebooting a system is an administrative task and for a multi-user system or server running critical processes, reboot or shutdown is a disruptive activity.
This article covers few such methods which can help you out with Linux reboot/shutdown activity.
GUI Method
If you’re using a GUI Desktop Environment for Linux like Gnome, KDE, Mate, XFCE, etc., you’ll find a power button in the system/application menu which offers actions such as logout, reboot, hibernate or power off. Available options may differ slightly depending upon which distribution, desktop environment, and version of OS is in use. But you’ll definitely find power-related settings in available menus to change the power state of your system.
For example, on my Ubuntu Mate desktop, I can find the Shut Down option in the power menu at the top right of my screen.
Once you select “Shut Down…” option, you’ll be presented with a dialog with multiple options like Suspend, Restart, Cancel and Shut Down. You can either proceed with Restart or Shut Down by clicking on the right button or cancel and get back to your desktop environment.
Offered GUI and options may differ slightly on the distribution and Desktop Environment you’re using but rest assured there is an option to change the power state of the system. And with GUI, it’s no more than few clicks in the power menu.
systemctl Command
On a Linux box running systemd as the init system, you can use systemctl command to reboot your machine.
$ sudo systemctl start reboot.target
Or you can simply use systemctl with required option, like for reboot as:
For initiating a shutdown, systemctl command goes like:
shutdown Command
shutdown command can be used to power down as well as reboot a Linux system. To reboot a system immediately use:
Or to power down a system without wait, use -h or -P flag:
We can add a delay to shutdown command to reboot/power off the system after a specified interval. This can be achieved as:
To halt a system without asking hardware to power off, you can use -H flag:
If you simply specify shutdown command, the shutdown will get scheduled after a minute. To shut down at specific time use:
In many cases, while a system is going down it’ll broadcast a message to the console of logged-in users. If you want to add your custom message in this broadcast, you can specify a message along with shutdown command as:
$ sudo shutdown 23:00 "Powering off system for maintenance. save your work"
To cancel a scheduled shutdown, you can use -c flag:
On some systems, shutdown command call systemctl in the backend to achieve desired reboot/shutdown operation.
Reboot Command
To gracefully reboot a system, you can also use reboot command (may need to use with sudo).
To power off the system with the reboot command, use -p flag:
To force a reboot (for systems not responding to normal reboot command), you can try -f flag as:
Halt Command
To halt a system, you can simply use halt command:
Poweroff Command
To power off a system, you have the option to use poweroff command:
init Command
For systems not running on systemd, init ( telinit will also work) command offers options to change the system’s run-level. To reboot a system using init , you can use:
Similarly to halt a system, the init command to use is:
Calling a specific run-level using init causes the system’s init process to execute a series of init scripts in a particular order to ensure the system reaches the desired run-level. Run-level 6 is defined for reboot while run-level 0 if for halting the system.
Power Button
For Linux running on a desktop or laptop, pressing the power button by default have the action of either putting the system to sleep or powering it down by sending the shutdown signal. This option can be tweaked from the system’s power settings. Although it should ideally be used as the last option if normal commands don’t work.
For a remote server running Linux, the power button usually powers off the system. But those located in remote data centers have the additional option to be rebooted or powered off from their remote lights-out management CLI/GUI tools offered by the respective server vendors.
Alt + SysRq Combination
For a non-responding, frozen system, it’s hard to bring it to a reboot or power off state. When you’ve no other option and as a last resort, you can try pressing Alt + PrintScreen + a sequence of keys in order to instantly reboot the system. It may not be a preferred or recommended option but nevertheless can be used as a last resort.
Always remember that there is possibility of data loss and corruption using this method as with any other non-graceful, forced reboot or shutdown option will have. Ensure system best practices for backups and redundancy and be careful when using this option.
For this option to work, it should have been enabled in the Linux kernel. You can check this by using below command:
An output of 1 indicates its enabled completely, while a number greater than indicates its partially enabled with some features. To enable it explicitly, you can use:
$ sudo echo “1” > /proc/sys/kernel/sysrq
To reboot a system using this method, keep holding Alt + SysRq (PrintScreen) and then press in sequence following keys after interval of few seconds between each key:
or to shutdown press O instead of B at the end:
- R: Switch keyboard from raw to XLATE mode
- E: Send SIGTERM signal to all processes except init
- I: Send SIGKILL signal to all processes except init
- S: Sync all mounted filesystems
- U: Remount all mounted filesystems as read-only
Lastly, we’ve either B or O which stands for:
Summary
So here go different ways that allow you to reboot or shut down a Linux system. It offers you options ranging from simple GUI interfaces to relatively complex terminal commands that can make your life easy or even allows you to automate stuff. For systems that froze for one reason or another, we discussed forced ways to achieve a reboot or shutdown state which may not be the ideal way but have to be used on rare occasions.
Take precautions while using the commands discussed in this article as they affect the system state and could possibly affect multiple users and services in the case of an enterprise server. Check out the man pages of commands suggested in this article to learn more about them and what all options they offer.
How to use Linux Shutdown Command with Examples
All Linux users and system administrators need to know how to shut down the entire system safely. There are several options to do so, including scheduling a shutdown at a specific time, shutting down immediately, broadcasting a unique message, and so on.
In this tutorial, learn how to use the Linux shutdown command with examples.
shutdown Command Syntax
Before going into specific ways to shut down your Linux system, you should understand the basic syntax of the shutdown command:
shutdown [options] [time] [message]
- [options] define whether you want to halt, power-off, or reboot the machine.
- [time] specifies when you want the shutdown to perform.
- [message] adds a message that announces the shutdown.
Note: If you need to reboot instead of shut down the system, refer to How To Restart Or Reboot Linux Server From The Command Line.
How to Use the shutdown Command
To use the shutdown command on Linux systems, a root user or a user with sudo privileges is required.
If you use the command without additional arguments, running sudo shutdown in a terminal window executes the shutdown in 60 seconds.
In the image below, see the output received after running the shutdown command.
Shutdown With All Parameters
To view all parameters when shutting down the Linux system, use the following command:
The output displays a list of shutdown parameters, as well as a description for each.
How to Shut Down the System at a Specific Time
To schedule a shutdown, add the [time] argument and specify when you want it to take place. There are two ways to shut down the system at a specific time – using the absolute or relative time format.
The absolute time follows the format hh:mm and allows you to schedule a shutdown at a specified time. The command follows the syntax:
For example, to require a shutdown at 7 AM in the morning, the command is:
Alternatively, use the relative format ( +m ) and schedule a shutdown in a defined number of minutes from the time you run the command. In that case, the command syntax is:
To shut down the system in 20 minutes, run:
How to Shut Down the System Immediately
As previously mentioned, running the shutdown command without any arguments prompts the system to shut down a minute after running the command. However, if you require an immediate shutdown, use:
Another option would be to schedule a shutdown using the relative time format with the value 0, as in the command below:
How to Broadcast a Custom Message
Once you schedule a system shutdown, all users within the system receive a message notifying them of the shutdown. To add a custom message to the shutdown notification to inform the users what is about to take place.
You can add a [message] only if the command also includes the [time] attribute:
sudo shutdown [time] "[message]"
For instance, to shut down the system in 20 minutes and broadcast the message System Upgrade, run:
sudo shutdown +20 "System Upgrade"
Note: Another way to broadcast messages to users in Linux is via the wall command.
How to Cancel a Scheduled Shutdown
To cancel a scheduled shutdown, use the command:
You can also add a message to notify users that the shutdown is canceled. To do so, add the [message] option (within quotations) to the command above. For example:
sudo shutdown -c "Canceling System Upgrade"
This article includes all the basic shutdown commands every Linux user should know. Utilizing this command is a safe way to shut down your system. Also, it is a useful method of informing all users about scheduled shutdowns.
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
In most modern Linux operating systems, managing a service is quite simple when it comes to basic commands.
A list of all the important Linux commands in one place. Find the command you need, whenever you need it or.
Vim allows you to delete entire lines, words or characters using various Vim commands. Learn the most.
Use the command line interface to display directory size and for display disk space. This guide will help you.