Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Why do we need the reboot function in different binaries?

shutdown -r

and

reboot

Or do they differ in something?

share|improve this question
1  
See unix.stackexchange.com/questions/8690/… 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 2:32

3 Answers 3

up vote 15 down vote accepted

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.

share|improve this answer
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

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

share|improve this answer

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.

share|improve this answer
    
reboot is in /sbin in Debian (with SysVinit) and Ubuntu (with upstart). –  Gilles 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 –  warl0ck Mar 3 '13 at 15:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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