Why do we need the reboot function in different binaries?
shutdown -r
and
reboot
Or do they differ in something?
Why do we need the reboot function in different binaries?
shutdown -r
and
reboot
Or do they differ in something?
We don't necessarily need them both, but we have them both because of the history of Unix, and its multiplicity of versions.
From their respective man pages:
shutdown is more general-purpose, and more powerful, while reboot is friendlier and easier to remember.
shutdown allows you to specify a temporal argument (to restart in 5 minutes, for instance) and allows you to do many things besides reboot, including:
However, if you just want to reboot the system now, it's easier to type reboot
than shutdown -r now
.
shutdown
use now as default. Do not try to get help for shutdown with shutdown -h
ever, especially not on a server somewhere in a datacenter.
– Residuum
Oct 10 '11 at 14:17
In addition to what iconoclast wrote, there's an important distinction between the two programs: shutdown
is in /sbin
, while reboot
is in /usr/bin
.
Why does this matter, you ask? I will tell you.
Things under /usr
are those that do not have to be available until the system is booted up far enough that the system is minimally functional. Top-level directories that are traditionally never mounted on separate filesystems — /bin
, /etc
, /sbin
, etc. — are expected to be available while the system is reaching this minimally useful state. There are various implications of this design; for instance, it is bad style to write the "stop" clause of a SysV init script that uses programs in /usr/bin
if there is an alternative in /bin
or /sbin
.
shutdown
is the key utility, the one always available. reboot
is a convenience utility only.
reboot
is in /sbin
in Debian (with SysVinit) and Ubuntu (with upstart).
– Gilles 'SO- stop being evil'
May 13 '11 at 21:16
The two commands do something different, however they can end up calling each other, which is why they seem to do the same thing!
reboot
will invoke the kernel to actually trigger a hardware reboot. However, it will only do this if the system is ready for shutdown - all daemons and user processes should be stopped, file systems unmounted, etc. So it checks the system runlevel, and if it's not 0 or 6, then it will actually invoke the shutdown
command for you.
shutdown
causes the system runlevel to be changed. The runlevel change (to 0 for halt or 6 for reboot) runs lots of scripts in /etc/rc0.d or rc6.d that shut down daemons, unmount filesystems, etc. Finally these scripts invoke halt
or reboot
- this time the system is in the correct runlevel and they instruct the kernel to reboot (or halt).