12

Why do we need the reboot function in different binaries?

shutdown -r

and

reboot

Or do they differ in something?

LanceBaynes
  • 40,135
  • 97
  • 255
  • 351
  • 1
    See http://unix.stackexchange.com/questions/8690/what-is-the-difference-between-halt-and-shutdown-commands for the distinction - the commands can behave differently depending on operating system (but generally do the same thing in Linux). – PleaseStand May 14 '11 at 02:32
  • As noted below and explained in detail at http://unix.stackexchange.com/a/196014/5132 , the premise of this question is false on systemd Linux operating systems. These are not different binaries on such systems. – JdeBP Apr 14 '15 at 09:47

3 Answers3

15

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:

  • The shutdown utility appeared in 4.0BSD.
  • A reboot utility appeared in Version 6 AT&T UNIX.

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:

  • you can just kick off users and not actually shutdown
  • you can put the system to sleep instead of shutting down
  • you can simply shutdown without rebooting (like the halt command)
  • you can include a custom warning message for users on the system

However, if you just want to reboot the system now, it's easier to type reboot than shutdown -r now.

iconoclast
  • 9,198
  • 13
  • 57
  • 97
  • 1
    Fun fact: Some versions of 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
6

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.

iconoclast
  • 9,198
  • 13
  • 57
  • 97
Warren Young
  • 72,032
  • 1
    reboot is in /sbin in Debian (with SysVinit) and Ubuntu (with upstart). – Gilles 'SO- stop being evil' May 13 '11 at 21:16
  • Okay, so meta-answer: know thy system. :) I use CentOS most often. – Warren Young May 13 '11 at 21:21
  • Same for Arch (systemd), both in /sbin – daisy Mar 03 '13 at 15:04
  • Indeed, on systemd Linux operating systems neither is the key utility, as with systemd all of these commands are (as the systemd doco has it) "compatibility" commands. Indeed, the premise of the question is false. They are not in different binaries. For details, see http://unix.stackexchange.com/a/196014/5132 . – JdeBP Apr 14 '15 at 08:04
6

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