How to mount and re-mount external drive on connection loss?

poisonborz

Member
May 8, 2020
25
2
23
55
For practical reasons I have my data folder on an external USB drive bind-mounted to the CTs/VMs. Like seemingly all external cases, sadly, this case sometimes also resets the connection to the PC (it's a brand case, has its own power, tride switching cable and ports) - but I don't really mind, as I'd also want to yank it out anytime without any preparation. Hence:

- how can I safely remove all mounts on a connection loss (to prevent data corruption)? I tried to make a udev/rules.d entry for a script but it said "the directory is in use" and didn't allow to execute.
- how can I remount the drive once the drive is connected again? I also tried to add a rules.d script with mount -a in it, to seemingly no effect. Also how should VMs be dealt with this case? Even if the drive is remounted, the bind mount points to an empty folder. Should the bind mount be recreated? Or restarting the instance is the only way?
 
Last edited: