I am working on an embedded Linux device with a USB hard drive. There is a swap file on this drive. The hard drive may be powered down at any moment before being powered back on few seconds later. This leads to various error messages, such as:
Write-error on swap-device
Kernel panic - not syncing: Attempted to kill init!
or exceptions in various applications, which is understandable since some page in/out requests failed. (Note that this kernel panic is also reproducible on a regular desktop Linux).
My goal is to somehow prevent this from happening and recover the system without rebooting the OS.
I can postpone the crash by calling scsi_block_requests, but I cannot keep them blocked forever.
I tried to kill some user mode tasks (using send_sig_info) in response to USB_DEVICE_REMOVE notification, but still keep getting exceptions.
I am also thinking whether it is possible to prevent SCSI device from being destroyed when USB device is removed, but keep it around and then somehow reconnect it to the new USB device, which will be created few seconds later when USB device is powered again. Since this is the same disk, then maybe I can resume all pending requests without re-mounting the disk.
What is your opinion? Can something like that be done? Or is it impossible to cleanly recover OS after hard drive removal?