10

On Linux (specifically, RHEL derivatives CentOS and Fedora), is there a difference?

echo b > /proc/sysrq-trigger

"Immediately reboot the system, without unmounting or syncing filesystems," according to Wikipedia.

reboot -n

"Don’t sync before reboot or halt. Note that the kernel and storage drivers may still sync," according to man 8 reboot. Is there actually any difference in this behavior?

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
sh-beta
  • 6,838
  • 7
  • 47
  • 66
  • Why would you vote to close this? – sh-beta Nov 28 '12 at 19:14
  • Test it and try it out ;) But really, why are you doing this? – ewwhite Dec 01 '12 at 18:19
  • I wish I'd seen this when it was asked; I'd migrate it over to the Unix stack exchange, but alas it's too old to be migrated :( If this is still a problem you're wanting an answer to I'd suggest re-posting there: http://unix.stackexchange.com/ – Mark Henderson Sep 24 '13 at 21:38

1 Answers1

15

The /sbin/reboot is a regular executable in the filesystem. If your filesystem is hosed (e.g. filesystem driver hang, SATA chipset hang or disk firmware hang), the changes for successfully executing that executable are slim to none. On the other hand, assuming that you have a root shell open already, echo b > /proc/sysrq-trigger does not need any filesystem access.

As long has echo is a shell built-in that should technically do fork() followed by open() for kernel internal virtual filesystem and a single write() which already results in system reboot after those 3 syscalls.

Mikko Rantalainen
  • 1,030
  • 14
  • 30
  • Well, echo also is a binary, right? I have stumbled upon situations where I Really need to reboot a server, and Really needs it to get rebooted and not getting stuck at some place during shutdown. So, instead of risking having to go to datacenter just issue echo b > /proc/sysrq-trigger. But usually I do: `$ sync; echo b > /proc/sysrq-trigger` `$ whereis echo echo: /usr/bin/echo /usr/share/man/man1p/echo.1p.gz /usr/share/man/man1/echo.1.gz` `$ whereis reboot reboot: /usr/sbin/reboot /usr/share/man/man2/reboot.2.gz /usr/share/man/man8/reboot.8.gz` – Stefan Feb 04 '20 at 10:16
  • 1
    `echo` is usually a shell builtin so it's available if you have shell prompt. Yes, `/bin/echo` exists, too, because by POSIX rules all commands must exists in the path but may be replaced by shell implementation to increase performance. The `echo` is used so often that only very very basic shells do not implement it. (Compare `help echo` vs `man echo`.) – Mikko Rantalainen Feb 12 '20 at 11:48