What is the difference between reboot , init 6 and shutdown -r now?
There is no difference in them. Internally they do exactly the same thing:
shutdowncommand (with the -r switch). The shutdown command used to kill all the running processes, unmount all the file systems and finally tells the kernel to issue the ACPI power command. The source can be found here. In older distros the reboot command was forcing the processes to exit by issuing the
SIGKILLsignal (still found in sources, can be invoked with
-foption), in most recent distros it defaults to the more graceful and init friendly
init 1 -> shutdown -r. This ensures that daemons clean up themselves before shutdown.
init 6tells the
initprocess to shutdown all of the spawned processes/daemons as written in the init files (in the inverse order they started) and lastly invoke the
shutdown -r nowcommand to reboot the machine
Today there is not much difference as both commands do exactly the same, and they respect the init scripts used to start services/daemons by invoking the shutdown scripts for them. Except for
reboot -f -r nowas stated below
There is a small explanation taken from manpages of why the
reboot -fis not safe:
-f, --force Force immediate halt, power-off, reboot. Don't contact the init system.
Forgot to mention, in upcoming RHEL distributions you should use the new
systemctlcommand to issue poweroff/reboot. As stated in the manpages of
shutdownthey are "a legacy command available for compatibility only." and the
systemctlmethod will be the only one safe.
Sometimes my reboot hangs at the SIGTERM, is there a way to know why, and also is there a way to timeout the reboot, such that if it takes too long, it will force a reboot?
Those RHEL versions are no longer "upcoming". ☺ As explained in more detail at http://unix.stackexchange.com/a/196014/5132, on such systemd operating systems there's no difference at all. They aren't even different programs.