2

Is running "reboot" command enough to reliably restart the Raspbian (Debian) system if filesystem/hdd is ok?

Will it work when there is an infinite loop in stop() function of rc script or if there are some defunct processes, 0 space left on root fs or almost zero free RAM?

Are there any situations (except filesystem/HW fault) where restart command is not enough and system will hang?

I know I can do something like this to restart reliably but I am not sure if it's safe from filesystem point of view - I don't care about stopping daemons:

# sync filesystem
echo s > /proc/sysrq-trigger
sleep 5

# remount fs read-only
echo u > /proc/sysrq-trigger
sleep 5

echo b > /proc/sysrq-trigger
  • Note that reboot does not work with some combinations of kernel and firmware, it will just cause a shutdown (and some other combinations will cause a reboot no matter what). – goldilocks Apr 8 '14 at 13:59
6

Is running "reboot" command enough to reliably restart the Raspian (Debian) system if filesystem/hdd is ok?

From the man page for reboot:

When called with --force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself and directly reboots the system. Otherwise this simply invokes the shutdown(8) tool with the appropriate arguments.

Assuming you don't fall into the first category (i.e. most normal cases of using the reboot command, assuming you don't pass the --force flag), shutdown will be invoked to gracefully bring the system down. This includes cleanly unmounting file systems and so forth, so you shouldn't have a problem.

Will it work when there is an infinite loop in stop() function of rc script or if there are some defunct processes, 0 space left on root fs or almost zero free RAM?

The Linux kernel is pretty good at terminating user-space processes which have hung or are occupying the processor in an infinite loop. If you watch the screen as you bring a Debian system down, you can occasionally see some red error messages when an application had to be force closed as part of the shutdown process.

Your mileage may vary if you have very little system RAM remaining, as this might prohibit you launching the reboot command in the first place. But this all depends on what you did to eat up all the system memory, and why you cannot back out of this situation before attempting to force a reboot.

You can have issues if you have been messing around in the kernel to the extent that the kernel cannot kill itself, but that is to be expected. A failed kernel module which holds the CPU in an infinite loop, for instance, will often not be receptive to forced killing during an attempted reboot.

I know I can do something like this to restart reliably but I am not sure if it's safe from filesystem point of view

The code you presented will work (see the first comment on this post), but as noted there, seems to be a little superfluous.


Ultimately, if you are using this system for development, you should certainly be taking appropriate backups of any critical data so you can recover more easily from a file-system crash, rather than worrying about how to avoid the crash in the first place.

  • 1
    While there could be filesystem activity occurring between the sync call and the remount call, it would not matter because the sync in this case is superfluous (i.e., unnecessary). The point of umount or mount -o remount (note that remount is not a real command) is to cleanly unmount or remount the filesystem, which will include an atomic sync. It will not simply discard cached data without writing to disk. So what the OP wants to do is perfectly safe, if partially pointless. – goldilocks Apr 8 '14 at 13:56
  • @goldilocks very good point - I've edited the post. – Cosmic Ossifrage Apr 8 '14 at 14:48
  • Note I don't think mount -o remount,ro is 100% equivalent to umount then mount again, meaning, it may not actually flush the disk cache immediately. The data will still be written to disk at an appropriate point (e.g. before an actual umount), even though the filesystem is read-only in userland, but don't think that because you've just remounted read-only it is now safe to physically disconnect storage or arbitrarily pull the plug. You still need to do a clean shutdown or actual umount. – goldilocks Apr 8 '14 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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