‘Shutdown’ versus ‘poweroff’ versus ‘halt’ on Ubuntu server
There seems to be a lot of confusion around how to properly restart or shut down your server under Ubuntu. The are several commands out there: halt, shutdown, poweroff and reboot. Which are the right ones to use and what are the differences?
Historically, halt, poweroff and reboot were fairly low-level commands that would do exactly what their command name implies. However, they would not gracefully take down your server – it was presumed that the server administrator would do that him- or herself before invoking these commands. Many newer Linux users were not familiar with the right usage scenarios and, as a result, the commands were changed to invoke shutdown, a gentler command that gracefully terminates any open processes by giving them an opportunity to complete tasks before exiting.
Since these commands now invoke shutdown, the following are equivalent:
Restarting your server
reboot is the same as
shutdown -r 0
Turning off your server
halt is the same as
poweroff is the same as
shutdown -P 0
Note that these commands need to be invoked as root or via the sudo command, e.g.
sudo halt.
The original usage of these commands is also available via the -f switch. So to invoke halt directly without going through shutdown, use sudo halt -f. This is not recommended unless you are sure all other processes have finished their work. Similarly, sudo shutdown 0 by itself is not very useful – in Ubuntu it drops the server into the Recovery Menu since all processes are terminated but the server is not asked to power down or restart. It can certainly be manually powered down or restarted from there, though. Also, instead of the 0 after shutdown you can use now or specify some other time (either in minutes from now or absolute time) for the server to shut down.
January 31st, 2010 at 8:56 am
[...] sudo poweroff See also ‘Shutdown’ versus ‘poweroff’ versus ‘halt’ on Ubuntu server [...]
August 14th, 2010 at 5:50 am
But… You didn’t mention the comparison between them and shutdown -H, and -h
August 14th, 2010 at 10:58 am
True. So here’ the explanation for that. From the man shutdown entry:
-h Requests that the system be either halted or powered off after
it has been brought down, with the choice as to which left up
to the system.
-H Requests that the system be halted after it has been brought
down.
This means that shutdown -H does not actually power the server off but puts the server in a state where it can be safely powered off by the admin. By comparion, shutdown -h may actually power the server off entirely if the system supports that.