I haven't found a clear answer to the differences between the two options to the command shutdown
.
Is halt
the same as shutdown -H
and poweroff
the same as shutdown -P
?
I haven't found a clear answer to the differences between the two options to the command shutdown
.
Is halt
the same as shutdown -H
and poweroff
the same as shutdown -P
?
It's a bit historical.
halt
was used before ACPI (which today will turn off the power for you)*. It would halt the system and then print a message to the effect of "it's ok to power off now". Back then there were physical on/off switches, rather than the combo ACPI controlled power button of modern computers.
poweroff
, naturally will halt the system and then call ACPI power off.
* These days halt
is smart enough to automatically call poweroff
if ACPI is enabled. In fact, they are functionally equivalent now.
/sbin/poweroff
is a symlink to /sbin/halt
.
– phunehehe
Jul 08 '12 at 08:10
shutdown
. Is command halt
the same as shutdown -H
, and command poweroff
the same as shutdown -P
? @phunehehe too.
– Tim
Jul 08 '12 at 12:17
halt
used to do just that. No orderly shutdown, just stop what the machine was doing right then and there. It was common to issue sync;sync;sync;halt
to make sure all buffers had been written out to disk.
– kurtm
Oct 27 '13 at 02:19
They're not the same thing, just very closely related. In practice, unless you want to specify a particular time to shutdown or to force an immediate unclean reboot/halt/poweroff, it really doesn't matter whether you run shutdown -h
or halt
... or shutdown -r
vs reboot
. Things weren't so nicely convenient in the past, but this is the way it works now (a lot of the opportunities for ambiguity or user error have been removed/smoothed out).
/sbin/shutdown
does a lot of "cleanup" stuff like notifying users, blocking new logins while the system is shutting down. It can also be told to shutdown the system at a certain time or in XX minutes - warning logged-in users every so often of the impending shutdown.
It also changes runlevel to 0
(halt
/poweroff
) or 6
(reboot
) which triggers the system to stop the running services, unmount disks, etc in preparation for the actual halt, poweroff, or reboot.
When all that is done, it then calls /sbin/halt
, /sbin/reboot
, or /sbin/poweroff
(reboot
and poweroff
are usually symlinks to halt
, which interprets them as halt -r
and halt -P
respectively).
Note, however, that if halt
/reboot
/poweroff
is called when the system is NOT in runlevel 0
or 6
then they will call shutdown
to do its job unless the -f
or force
option is used.
(The details of how run-levels are interpreted may vary from distro to distro, but 0
and 6
are used as described here in Debian and Debian-derivatives like Ubuntu).
See the man pages for shutdown
and halt
for more info.
Finally, the distinction between halt
and poweroff
state is that halt
does everything up to actually powering the machine off (on some kinds of hardware this means it drops into a ROM bootloader or similar. On most PC hardware it just halts), while poweroff
completes that final step and switches off. reboot
, of course, gets to the halt state and then reboots the computer.
BTW, the default is typically to either poweroff
or reboot
, but you can use -H
as an argument to shutdown
to make it halt instead. This isn't very useful on PC-based linux boxes (but is useful on machines, like sparc boxes, that have a firmware boot monitor. It's possible it may become useful on newer machines with an EFI command line).
shutdown
commands have the notion of run levels. shutdown
mostly does not invoke halt
/reboot
/poweroff
; ironically it is on a few non-Linux systems where this received wisdom still remains true today. And where the symbolic links point is not necessarily halt
; not only that, in some toolsets they are not symbolic links at all. See http://unix.stackexchange.com/a/196471/5132 for more details.
– JdeBP
Apr 15 '15 at 23:01