11

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?

3
  • Why would you vote to close this?
    – sh-beta
    Nov 28, 2012 at 19:14
  • Test it and try it out ;) But really, why are you doing this?
    – ewwhite
    Dec 1, 2012 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: unix.stackexchange.com Sep 24, 2013 at 21:38

1 Answer 1

16

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.

2
  • 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 4, 2020 at 10:16
  • 2
    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.) Feb 12, 2020 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .