Home » What is the difference between Halt and Shutdown commands?

What is the difference between Halt and Shutdown commands?

Solutons:


Generally, one uses the shutdown command. It allows a time delay and warning message before shutdown or reboot, which is important for system administration of multiuser shell servers; it can provide the users with advance notice of the downtime.

As such, the shutdown command has to be used like this to halt/switch off the computer immediately (on Linux and FreeBSD at least):

shutdown -h now

Or to reboot it with a custom, 30 minute advance warning:

shutdown -r +30 "Planned software upgrades"

After the delay, shutdown tells init to change to runlevel 0 (halt) or 6 (reboot). (Note that omitting -h or -r will cause the system to go into single-user mode (runlevel 1), which kills most system processes but does not actually halt the system; it still allows the administrator to remain logged in as root.)

Once system processes have been killed and filesystems have been unmounted, the system halts/powers off or reboots automatically. This is done using the halt or reboot command, which syncs changes to disks and then performs the actual halt/power off or reboot.

On Linux, if halt or reboot is run when the system has not already started the shutdown process, it will invoke the shutdown command automatically rather than directly performing its intended action. However, on systems such as FreeBSD, these commands first log the action in wtmp and then will immediately perform the halt/reboot themselves, without first killing processes or unmounting filesystems.

The past

In the 1980s, the BSDs had halt, reboot, and shutdown. System 5 UNIX had a BSD compatibility toolset. But natively it had its own, different, shutdown command; and didn’t have halt or reboot at all. (Some System 5 variants had things like SCO XENIX’s haltsys.)

The BSD halt and reboot commands were low-level, drastic, and immediate. The considerate way to shut down a BSD system was the shutdown command, which did all of the things that one expects to happen: wall messages to users, services gracefully killed, log entries written, logins disabled, and so forth.

Whilst the BSDs were largely where the received wisdom originated that “shutdown execs halt/reboot“, and that the latter were to be used with care; it was the System 5 world where people learned the contrary habit that halt/reboot were just handy shorthands and nothing more: /usr/ucb/halt, from the “BSD Compatibility Package”, was no different in effect to shutdown -h. They both ended up doing init 0.

Further reading

  • halt. 1982-05-11. 4.2BSD manual.
  • haltsys. 2005-06-03. SCO OpenServer manual.
  • AT&T (1990). UNIX System 5 Release 4: BSD/XENIX Compatibility Guide. Prentice Hall.
  • AT&T (1990). UNIX System 5 Release 4: System Admninistrators’ Guide. Prentice Hall.

Today

Nowadays, we have a range of possible system management toolsets. The BSDs still have their toolset, albeit purged of any possible AT&Tisms in the 1990s. Miquel van Smoorenburg in 1992 (re-)wrote a Linux init+rc, and their associated tools, which people now refer to as “System 5 init”, even though it isn’t actually the software from UNIX System 5 (and isn’t just init). There are also systemd, upstart, and nosh, each of which have their own implementations of halt, reboot, fasthalt, fastboot, and so forth.

The toolsets have also grown and changed. There’s now a poweroff command, not present in 1980s operating systems because the Central Processing Units on most contemporary machines had no way of controlling their power supplies. Linux toolsets in particular have aquired the BSD commands; but like the BSD compatibility tools on UNIX System 5, they aren’t exact workalikes and things have been largely flattened.

This flattening has brought us to the point where halt and shutdown are mostly the same. But the exact details vary from toolset to toolset, and the mechanics of each toolset are all slightly different.

It has also brought us to the slightly embarrassing position where this command set has become so festooned with compatibility options that it now allows people to give computers self-contradictory instructions like reboot --halt and poweroff --reboot, as I noted in the manual page for the nosh halt, fasthalt, reboot, fastboot, and poweroff commands. ☺

The systemd toolset

halt, reboot, poweroff, telinit, and shutdown are all one program. It’s actually systemd’s own systemctl program. It has several command line parsers for the various command line syntaxes of those commands, as well as its own, but after that largely funnels into one code path internally. There’s no difference between using halt and its command options to trigger an action and using shutdown and its command options to trigger the same action.

systemd does not consider rescue mode (which is what the systemd people have renamed single user mode) to be a shut down system state, and it is not reachable with any of these commands. Option-less shutdown now is the same as poweroff.

Further reading:

  • https://unix.stackexchange.com/a/196014/5132 .

The BSDs

The BSDs largely retain their 1980s semantics. halt and shutdown are thus very much not equivalent in their toolsets. halt and reboot are one single program; and are still low level, immediate, and drastic. Whereas shutdown and poweroff, also one single program, do all of the considerate things like scheduled shutdown, writing wall messages, logging actions, disabling login, and so forth.

In the BSD toolsets, shutdown/poweroff traditionally ended up invoking halt/reboot to enact the final system state change. The (often nowadays incorrect) received wisdom that “shutdown execs halt/reboot” in fact still holds on NetBSD and OpenBSD. But on FreeBSD/TrueOS/DragonFlyBSD it is only the case if the -o option is used. On these BSDs, both of these programs normally enact the final system state change by sending various signals (INT, USR1, and USR2) to process #1. init does all system state management on on these systems.

On all of them, option-less shutdown now is not equivalent to any of halt, reboot, or poweroff. It transitions to the BSD single user mode, from which one can transition back to multi-user mode.

Further reading:

  • shutdown. System Manager’s Manual. NetBSD Manual pages. 2011-11-04.
  • reboot, halt. OpenBSD Manual pages. 2016-09-03.
  • shutdown. FreeBSD Manual pages. 2016-09-21.
  • reboot, halt, fastboot, fasthalt. FreeBSD Manual pages. 2017-03-19.
  • shutdown. System Manager’s Manual. DragonFlyBSD Manual pages. 2016-09-29.
  • reboot, halt, fastboot, fasthalt. System Manager’s Manual. DragonFlyBSD Manual pages. 2016-09-29.

The nosh toolset

In the nosh system management toolset, halt, fasthalt, poweroff, fastpoweroff, reboot, and fastboot are all one program. It’s a backwards compatibility shim that normally simply chains to shutdown, the opposite of received wisdom. The --force option makes it chain to system-control instead.

So there’s no difference (absent --force) between the halt command and the shutdown command (with the equivalent option) in this toolset, as this set of “BSD/System 5 compatibility” commands is simply a thin shim layer over the top of shutdown.

Further reading:

  • Jonathan de Boyne Pollard (2018). shutdown. nosh toolset manual pages. Softwares.
  • Jonathan de Boyne Pollard (2018). telinit, init, reboot, halt, haltsys, powercycle, poweroff, … fastboot, fasthalt, fastpowercycle, fastpoweroff, … nosh toolset manual pages. Softwares.

The upstart toolset

Like with nosh, in the upstart system management toolset the opposite of received BSD wisdom applies. halt, reboot, and poweroff are all one program, that normally chains to shutdown; unless the --force option is used, which makes it make the reboot() system call itself.

So, again, there’s no difference (absent --force) between the halt command and and shutdown command (with the equivalent option) in this toolset. Also again, option-less shutdown now (which none of halt, reboot, or poweroff can end up invoking as they all set options) brings the system into single user mode rather than shutting it down.

Further reading:

  • Scott James Remnant. shutdown(8). Ubuntu manual pages.
  • Scott James Remnant. reboot(8), halt(8), poweroff(8). Ubuntu manual pages.

The Linux System 5 init+rc toolset

Again, in this toolset the opposite of received BSD wisdom applies and halt and reboot simply chain to shutdown — unless the system is already in the poweroff or halt “run-levels”, in which case these commands actually enact the final system state change. shutdown in its turn chains to init.

So, again, there’s no difference (unless the system is already largely shut down) between halt and shutdown because the former just invokes the latter. And yes, again, option-less shutdown now (which none of halt, reboot, or poweroff can end up invoking as they all set options) brings the system into single user mode rather than shutting it down.

I suspect this is somewhat dependant on which version of UNIX/Linux you are using. On Centos (and I expec other modern Linux) halt calls shutdown (providing you’re not at runlevel 0 or 6) so your system will be shutdown cleanly. On Solaris 10 halt is more brutal, it just flushes the disk caches and powers off the system – no attempt is made to run any scripts or shutdown smf facilities.

Related Solutions

Joining bash arguments into single string with spaces

[*] I believe that this does what you want. It will put all the arguments in one string, separated by spaces, with single quotes around all: str="'$*'" $* produces all the scripts arguments separated by the first character of $IFS which, by default, is a space....

AddTransient, AddScoped and AddSingleton Services Differences

TL;DR Transient objects are always different; a new instance is provided to every controller and every service. Scoped objects are the same within a request, but different across different requests. Singleton objects are the same for every object and every...

How to download package not install it with apt-get command?

Use --download-only: sudo apt-get install --download-only pppoe This will download pppoe and any dependencies you need, and place them in /var/cache/apt/archives. That way a subsequent apt-get install pppoe will be able to complete without any extra downloads....

What defines the maximum size for a command single argument?

Answers Definitely not a bug. The parameter which defines the maximum size for one argument is MAX_ARG_STRLEN. There is no documentation for this parameter other than the comments in binfmts.h: /* * These are the maximum length and maximum number of strings...

Bulk rename, change prefix

I'd say the simplest it to just use the rename command which is common on many Linux distributions. There are two common versions of this command so check its man page to find which one you have: ## rename from Perl (common in Debian systems -- Ubuntu, Mint,...

Output from ls has newlines but displays on a single line. Why?

When you pipe the output, ls acts differently. This fact is hidden away in the info documentation: If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is...

mv: Move file only if destination does not exist

mv -vn file1 file2. This command will do what you want. You can skip -v if you want. -v makes it verbose - mv will tell you that it moved file if it moves it(useful, since there is possibility that file will not be moved) -n moves only if file2 does not exist....

Is it possible to store and query JSON in SQLite?

SQLite 3.9 introduced a new extension (JSON1) that allows you to easily work with JSON data . Also, it introduced support for indexes on expressions, which (in my understanding) should allow you to define indexes on your JSON data as well. PostgreSQL has some...

Combining tail && journalctl

You could use: journalctl -u service-name -f -f, --follow Show only the most recent journal entries, and continuously print new entries as they are appended to the journal. Here I've added "service-name" to distinguish this answer from others; you substitute...

how can shellshock be exploited over SSH?

One example where this can be exploited is on servers with an authorized_keys forced command. When adding an entry to ~/.ssh/authorized_keys, you can prefix the line with command="foo" to force foo to be run any time that ssh public key is used. With this...

Why doesn’t the tilde (~) expand inside double quotes?

The reason, because inside double quotes, tilde ~ has no special meaning, it's treated as literal. POSIX defines Double-Quotes as: Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the...

What is GNU Info for?

GNU Info was designed to offer documentation that was comprehensive, hyperlinked, and possible to output to multiple formats. Man pages were available, and they were great at providing printed output. However, they were designed such that each man page had a...

Set systemd service to execute after fstab mount

a CIFS network location is mounted via /etc/fstab to /mnt/ on boot-up. No, it is not. Get this right, and the rest falls into place naturally. The mount is handled by a (generated) systemd mount unit that will be named something like mnt-wibble.mount. You can...

Merge two video clips into one, placing them next to each other

To be honest, using the accepted answer resulted in a lot of dropped frames for me. However, using the hstack filter_complex produced perfectly fluid output: ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4 ffmpeg -i input1.mp4 -i input2.mp4...

How portable are /dev/stdin, /dev/stdout and /dev/stderr?

It's been available on Linux back into its prehistory. It is not POSIX, although many actual shells (including AT&T ksh and bash) will simulate it if it's not present in the OS; note that this simulation only works at the shell level (i.e. redirection or...

How can I increase the number of inodes in an ext4 filesystem?

It seems that you have a lot more files than normal expectation. I don't know whether there is a solution to change the inode table size dynamically. I'm afraid that you need to back-up your data, and create new filesystem, and restore your data. To create new...

Why doesn’t cp have a progress bar like wget?

The tradition in unix tools is to display messages only if something goes wrong. I think this is both for design and practical reasons. The design is intended to make it obvious when something goes wrong: you get an error message, and it's not drowned in...