Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a small embedded Linux device where the root filesystem is mounted over a USB connection

the device can handle a reset quite well (it'll wait for the USB disk to arrive should it be unplugged at boot)

however should the disk be unplugged the device tends to wedge, I'd prefer if it just reset?

is there a kernel option that would get the kernel to reset should the primary disk disappear?

share|improve this question
2  
1. Why not use RAID to avoid the failure problem? 2. Why not have the system load a RAM disk from the USB Boot device, so that it doesn't need the USB Stick once it's running? 3. Why would the USB drive not be plugged directly into the motherboard or something incredibly secure so that it never comes out with extreme intention? –  Chris S Dec 18 '12 at 1:57
    
Perhaps a custom udev rule to intiate a reboot when the device is removed? –  fukawi2 Dec 18 '12 at 2:03
add comment

migrated from serverfault.com Dec 18 '12 at 2:10

This question came from our site for professional system and network administrators.

1 Answer

This is quite easy.

You'll need to create a udev rule triggered on the USB unplug event for that device. These would be files in etc/udev/rules.d. Take a look at this question over at ServerFault for details.

So, we've established that you can trigger arbitrary commands on USB unplug events with the PROGRAM keyword.

The second part to this is to use the "magic" sysrq key. See this article about Magic SysRq on Wikipedia for things you can do with the sysrq key. The key can also be triggered by echoing the letter of the action to /proc/sysrq-trigger. This will have the same effect as pressing the key combination on your physically attached keyboard.

Therefore, the udev rule would be:

DRIVER="some_device", ACTION="remove", PROGRAM="/bin/echo b > /proc/sysrq-trigger"

This will trigger the system to reboot when the device some_device is removed.

And this of course assumes that by "wedged" you don't mean "kernel panic".

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.