2

IMPORTANT: I am able to restore halt old behavior if I do:

apt install sysvinit-core  

Plus: Old Red Hat based versions are able to power off with halt too.

I am trying to understand why in Debian 9 you should not use halt to turn off your computer anymore. That behavior are removed from systemd. I am a bit scary, but I think there must be a good logical reason.

Are other unixes or unix-like with this same behavior or are Linux turning into something different?

Now if you want to turn off the machine after the system shutdown you should use poweroff instead of halt...

Somebody know how this command are interpreted in other Unix-Like?

That is not a duplicated, because, debian 7 can power off with halt for example.

10
  • 1
    Plain halt powers off a macOS system, but not an OpenBSD system. halt is not a POSIX utility, nor is poweroff or shutdown or any similar utility. – Kusalananda Mar 14 '19 at 18:30
  • @LucianoAndressMartini does this help? What is the difference between these commands for bringing down a Linux server? – terdon Mar 14 '19 at 19:08
  • 1
    @DopeGhoti I don't think this is a dupe. The OP wants to know why this change happened, not what the difference between halt and shutdown may be. – terdon Mar 14 '19 at 19:10
  • 1
    Yes, exactly, I am trying to understand why this change happened. Thank you. – Luciano Andress Martini Mar 14 '19 at 19:35
  • 1
    halt allows for the system to be halted with diagnostic kernel messages still visible on the console on some systems; this is the reason for a distinction between halt and poweroff to exist at all. – DopeGhoti Mar 14 '19 at 21:42
6

Debian

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 HALT=poweroff.

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

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/halt or /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 halt command.

Historical note

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.)

2
  • Yes that is what I am expecting! Very nice informations! Thank you a lot, specially about the notes about Red Hat doing the same behavior in older versions! – Luciano Andress Martini Mar 18 '19 at 18:04
  • To solve all this problems and others, I just migrated to devuan, I am so happy with this system that I cannot explain. – Luciano Andress Martini Mar 21 '19 at 20:26
3

This question is predicated upon multiple falsehoods.

One did not use halt to turn off one's computer, and this has not changed with systemd.

halt a.k.a. haltsys shuts down and halts. poweroff is a newer command that shuts down and powers off. (https://unix.stackexchange.com/a/196471/5132 explains the subtleties of this which I am going to gloss over here, since the question is only about Linux operating systems. This answer focuses on just the AT&T System 5 UNIX side of the universe.)

As I explained at https://superuser.com/a/900205/38062, computers are not necessarily able to power off under software control. The action of the haltsys and halt command has conventionally been to shutdown and halt the machine, the next action being the operator using a physical reset button or power switch.

halt gained a -p/--poweroff option to make it equivalent to poweroff, but this is symptomatic of a general growth of overlapping and self-contradictory options to these commands. Witness the manual page for the Upstart halt command in Debian 7. There's halt --poweroff there. The manual page for the van Smoorenburg halt command in Debian 7 similarly has halt -p.

But this is not something that has changed with systemd. systemd provides the same. The systemd halt command also has --poweroff. It furthermore has --reboot and (for good measure) --halt options.

I had to do the same with the halt/haltsys command in the nosh toolset, for compatibility.

You may erroneously think that plain old halt powered off your computer. But that was unequivocally wrong for Upstart, and only true for the van Smoorenburg toolset if you happened to hit a bug.

The bug, which has only this year finally been fixed, was that the van Smoorenburg halt command would simply ignore the presence or absence of the -p option and instead decide whether to halt or power off according to the value of a setting in /etc/default/halt. If you happened to have that setting set to power off, then halt would always power off, even if no -p option were supplied. Conversely, if you happened to have that setting set to halt, then halt would always halt, even if a -p option were supplied.

But this was a bug, not the documented nor intended behaviour, not the behaviour of every halt command that was available on Debian, and not the conventional behaviour of the halt command in general.

Further reading

3
  • A falsehood that running apt install sysvinit-core turned true! Why? I just installed sysvinit, and at end halt says "Will now halt" exactly in that moment the machine powered off, how could this be a falsehood, it looks like the developer of sysvinit still has this falsehood! and plus that halt -f turns off the machine immediately. – Luciano Andress Martini Mar 18 '19 at 11:49
  • 1
    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 HALT=poweroff. 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. – telcoM Mar 18 '19 at 13:00
  • 1
    @telcoM Thank you very much for this! That is enough for me, if you put that as a answer I will mark it as the correct answer. (Note one thing (not very important), CentOS seems to have the same behavior in my old servers). Can you post this as a answer please? – Luciano Andress Martini Mar 18 '19 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.