When using SysVinit in Debian(esque) systems,
/etc/defaults/halt includes a variable that defines whether the system will run halt or poweroff at the end of transition to runlevel 0. The default setting is
Before SysVinit 2.74 you were not supposed to run
halt directly, and starting from that version, the SysVinit
halt command will just call
shutdown -h unless the current runlevel is 0 or 6. This is documented in
halt(8) man page. At the end of transition to runlevel 0 the runlevel scripts will run
$HALT, which is equal to
poweroff by default.
RHEL/CentOS 5 was the last version to use SysVinit: version 6 used
upstart and version 7 uses
systemd. In RHEL 5.11, the last script to run when transitioning to runlevel 0 is
/etc/init.d/halt, and its last lines are:
[ "$INIT_HALT" != "HALT" ] && HALTARGS="$HALTARGS -p"
exec $command $HALTARGS
Since the same script is also run at the end of transition to runlevel 6 (reboot), the actual command to run is defined by the variable
$command, and it will be either
/sbin/reboot. According to the value of the
$INIT_HALT variable, the script will decide whether or not add the
-p option. That variable is set by
/sbin/shutdown. The RHEL 5.11
shutdown(8) man page says:
HALT OR POWEROFF
The -H option just sets the init environment variable INIT_HALT to HALT, and the -P option just sets that variable to POWEROFF. The shutdown script that calls halt(8) as the last thing in the shutdown sequence should check these environment variables and call halt(8) with the right options for these options to actually have any effect.
Debian 3.1 (sarge) supports this.
(Yes, the RHEL 5.11 man page mentions Debian 3.1! I guess someone at RedHat porting patches from various sources to RHEL missed one reference...)
It looks like RedHat has decided to code the above-mentioned test in the
/etc/init.d/halt script in such a way that switching off the power (using
/sbin/halt -p at the end of shutdown) is the default halt action: the only way to achieve halt without poweroff is to use the upper-case
-H option of the
shutdown command to explicitly request it, e.g.
shutdown -hH now
But again, the default powerdown is triggered by the runlevel scripts customized by the Linux distribution, so it's not really a feature of the SysVinit
Old SysVinit-using systems (both Linux and non) used to have several commands that were not intended to be used directly, but only as part of the appropriate shutdown/reboot scripts. Before SysVinit 2.74, the
/sbin/halt command with no options would have done the same as
halt -f of modern SysVinit does, i.e. a brutal, immediate kernel shutdown without stopping any services or unmounting filesystems.
For the same reason, being used to the Linux
killall command can be dangerous on other Unixes. Its man page even has this ominous warning:
Be warned that typing killall name may not have the desired effect on non-Linux systems, especially when done by a privileged user.
This is because the classic SystemV
killall was one of those commands designed to be used only as part of a shutdown script. In Linux distributions with SysVinit, the classic version of the command may be found as
killall5. It literally kills all processes except kernel threads and processes in its own session: its intended use is in a shutdown script after shutting down all services, just before unmounting the local filesystems, to kill of any other processes that might delay or prevent the unmounting.
(How I know this, you ask? Well, I once made the mistake of running
killall <something> as root on a Solaris 2.6 system. A very effective learning experience.)