0

I'm using an m2 SSD in a USB C enclosure as a root partition on Linux. Despite trying different enclosure brand, there are always some rare disconnection (when moving the cable for example).

A quick disconnect will always force remount the partition readonly and won't be recoverable (eg: I would need to reboot).

Back in the days, with e-SATA, disconnecting the disk would freeze I/O, but everything would be back to a working state after reconnecting the drive. This is also similar to the hard mount option for NFS.

Is there a way to achieve with an USB storage device - freeze the I/O during disconnect instead of remounting the partition readonly and returning I/O errors for I/O calls?

3
  • Which filesystem do use? What os and distribution?
    – Turdie
    Commented Dec 24, 2023 at 13:26
  • 1
    That seems likely to cause damage to the SSD, eventually!! Find out what causes that disconnection, e.g., a partially unsoldered USB connector on the PC, or a bad hub, and fix it. Though I've had powered hubs go off-and-on, I've never had a directly connected external drive do so. Commented Dec 24, 2023 at 18:47
  • If you have a spare gig or two of ram, you might consider running your system live toram (from a live ISO copied to ram). Then you can physically unplug every storage drive with no issues, if you wanted. Of course, you would have to mount a physical drive to save any changes since all root filesystem writes are only to temporary ram (tmpfs) files.
    – Xen2050
    Commented Dec 25, 2023 at 4:21

1 Answer 1

1

While I haven't dug deeper, I suspect that SATA (the way it works on Linux) has an advantage in that the "SCSI targets" are static; each SATA port has a static mapping. That doesn't work with USB storage, where the SCSI targets are not known upfront (and thanks to USB hubs, a single USB port can lead to multiple storage devices, as well as the ports themselves will come and go).

(I also kind of suspect that your previous machine didn't handle SATA hotplug completely (even though it should have, for an eSATA port) and thought that the disk was still connected, merely not responding.)

It should be possible to achieve what you want through the Device-mapper subsystem (which powers LVM and LUKS among other things). If you set up even just a simple dm-linear device that's a 1:1 mapping of the underlying 'sda' device, then mount the dm device instead, it will be possible to change where the dm device is mapped to without the filesystem noticing anything at all. That is, if /dev/sda disappears, dmsetup suspend --noflush would suspend I/O and dmsetup reload could be used to switch it over to another backing device. I have not tried this myself. (I also don't know whether you need to do it manually or whether LVM could do it all for you.)

2
  • Very interesting. Although I wonder if the whole root filesystem disappears, would access to dmsetup disappear as well
    – Xen2050
    Commented Dec 25, 2023 at 4:18
  • Possibly, but the tools could be copied to an in-memory tmpfs on boot (e.g. to somewhere in /run). Commented Dec 25, 2023 at 13:01

You must log in to answer this question.

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