Why does "shutdown -r now" behave differently from "reboot -f" on Debian Linux?

I've recently had to deal with a pesky, intermittent NFS client/server hung mount point issue. When the problem occurs on the client I cannot unmount, along with some other odd behavior. The only immediate resolution I have to date is to reboot the client box.

But shutdown -r now does not work at all. I've since discovered reboot -f, which does reboot the system. Why? I've read the man pages but nothing seems to answer my question.

Why Does shutdown -r now behave differently than reboot -f?

(I'm continuing to resolve the NFS issue, but that is not my question here.)


Solution 1:

From the shutdown man page:

Once TIME has elapsed, shutdown sends a request to the init(8) daemon to bring the system down into the appropriate runlevel.

init starts and stops jobs as the system changes runlevels. When entering runlevel 6 due to a reboot, the system runs all the scripts in /etc/rc6.d. Since your system is not responding to shutdown, it's likely a script in /etc/rc6.d (possibly K05nfs-common given your NFS issues) is stuck, not allowing the shutdown sequence to finish. In fact, the last thing init runs when changing to runlevel 6 is reboot -d -f -i.

reboot -f skips all the scripts and reboots the system directly.

Solution 2:

shutdown instructs init to begin the shutdown procedure, which involves letting logged in users know that the system is shutting down, killing all the processes gracefully, unmounting and syncing drives, and so on. You're getting hung up here because processes stuck waiting for IO tend to be very hard to kill, and your stuck NFS mount can't be unmounted.

reboot -f, on the other hand, immediately reboots the server without doing any of that. (reboot is the program init calls to shut down the server. Without the -f flag, it will check to see if init thinks it is currently rebooting, and if not, it will call shutdown instead to start the process).

Solution 3:

Because 'reboot -f' does not go into runlevel 0 - it tells the OS to reinitialise the CPU directly. Man page on my nearest Linux box says:

 -f     Force halt or reboot, don't call shutdown(8)

The shutdown man page explains more.

Solution 4:

If you use the intr option on your NFS mounts, then shutdown -r now should be able to kill processes waiting on NFS IO to complete. This may result in file corruption, but likely no more than shutdown -f creates.