And now, the systemd answer.
You're using, per the tag on your question, Red Hat Enterprise Linux. Since version 7, that has used systemd. None of the other answers are correct for the world of systemd; nor even are some of the assumptions in your question.
- Forget about runlevels; they exist, but only as compatibility shims. The systemd documentation states that the concept is "obsolete". If you're starting to learn this stuff on a systemd operating system, don't start there.
- Forget about the manual page that marcelm quoted; it's not from the right toolset at all, and is a description of another toolset's command, incorrect for systemd's. It's the one for the
halt
command from the van Smoorenburg "System 5" init
utilities.
- Ignore the statements that
/sbin/halt
is a symbolic link to /sbin/reboot
; that's not true with systemd. There is no separate reboot
program at all.
- Ignore the statements that
halt
or reboot
invoke a shutdown
program with command-line arguments; they are also not true with systemd. There is no separate shutdown
program at all.
Every system management toolset has its version of these utilities. systemd, upstart, nosh, van Smoorenburg init
, and BSD init
all have their own halt
, poweroff
, and so forth. On each their mechanics are slightly different. So are their manual pages.
In the systemd toolset halt
,poweroff
,reboot
, telinit
, and shutdown
are all symbolic links to /bin/systemctl
. They are all backwards compatibility shims, that are simply shorthands for invoking systemd's primary command-line interface: systemctl
. They all map to (and in fact are) that same single program. (By convention, the shell tells it which name it has been invoked by.)
targets, not runlevels
Most of those commands are shorthands for telling systemd, using systemctl
, to isolate a particular target. Isolation is explained in the systemctl
manual page (q.v.), but can be, for the purposes of this answer, thought of as starting a target and stopping any others. The standard targets used in systemd are listed on the systemd.special
(8) manual page.
The diagrams on the bootup
(7) manual page in the systemd toolset, in particular the last one, show that there are three "final" targets that are relevant here:
halt.target
— Once the system has reached the state of fully isolating this target, it will have called the reboot(RB_HALT_SYSTEM)
system call. The kernel will have attempted to enter a ROM monitor program, or simply halted the CPU (using whatever mechanism is appropriate for doing so).
reboot.target
— Once the system has reached the state of fully isolating this target, it will have called the reboot(RB_AUTOBOOT)
system call (or the equivalent with the magic command line). The kernel will have attempted to trigger a reboot.
poweroff.target
— Once the system has reached the state of fully isolating this target, it will have called the reboot(RB_POWER_OFF)
system call. The kernel will have attempted to remove power from the system, if possible.
These are the things that you should be thinking about as the final system states, not run levels. Notice from the diagram that the systemd target system itself encodes things that are, in other systems, implicit rather than explicit: such as the notion that each of these final targets encompasses the shutdown.target
target, so that one describes services that must be stopped before shutdown by having them conflict with the shutdown.target
target.
systemctl
tries to send requests to systemd-logind
when the calling user is not the superuser. It also passes delayed shutdowns over to systemd-shutdownd
. And some shorthands trigger wall
notifications. Those complexities aside, which would make this answer several times longer, assuming that you are currently the superuser and not requesting a scheduled action:
systemctl isolate halt.target
has the shorthands:
shutdown -H now
systemctl halt
- plain unadorned
halt
systemctl isolate reboot.target
has the shorthands:
shutdown -r now
telinit 6
systemctl reboot
- plain unadorned
reboot
systemctl isolate poweroff.target
has the shorthands:
shutdown -P now
telinit 0
shutdown now
systemctl poweroff
- plain unadorned
poweroff
systemctl isolate rescue.target
has the shorthands:
telinit 1
systemctl rescue
systemctl isolate multi-user.target
has the shorthands:
telinit 2
telinit 3
telinit 4
systemctl isolate graphical.target
has the shorthand:
After parsing the various differing command-line syntaxes, these all eventually end up in the same code paths inside the systemctl
program.
Notes:
- The traditional behaviour of option-less
shutdown now
has been to switch to single-user mode. This is not the case with systemd. rescue.target
— single-user mode being renamed rescue mode in systemd — is not reachable with the shutdown
command.
telinit
really does wholly ignore all of those runlevelN.target
and default.target
symbolic links in the filesystem that the manual pages describe. The aforegiven mappings are hardwired into the systemctl
program, in a table.
- systemd has no notion of a current run level. The operation of these commands is not conditional upon any "if you are in run-level N".
- The
--force
option to the halt
, reboot
, and poweroff
commands is the same as saying --force --force
to the systemctl halt
, systemctl reboot
, and systemctl poweroff
commands. This makes systemctl
try to call reboot()
directly. Normally it just tries to isolate targets.
telinit
is not the same as init
. They are different programs in the systemd world, the latter being another name for the systemd
program, not for the systemctl
program. The systemd
program is not necessarily compiled with any van Smoorenburg compatibility at all, and on some systemd operating systems complains about being invoked incorrectly if one attempts init N
.
Further reading