I'm using the RPI2 with Raspbian Jessie.
I made a C++ program which records video file on a USB dongle (/dev/sda1 mounted to /media/usb1)
I would like to be able to replace the USB dongle while my program is running. (hot swap)
Therefore, I think that my USB dongle must always stays on /dev/sda1.
To do so, I'm trying to use udev rules but It does not work. Right now, if my program is running while I perform the USB dongle exchange, then I got devices in /dev/sda, /dev/sdb, /dev/sdb1.
I created two udev rules files:
First, udev rule to force the device to be always: /dev/sda
sudo nano /etc/udev/rules.d/10-local.rules
KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{product}=="Cruzer Fit",
SYMLINK+="sda%n"
Second, udev rule to unmount or mount depending of the usb event:
sudo nano /etc/udev/rules.d/automount.rules
# automounting usb flash drives
# umask is used to allow every user to write on the stick
# we use --sync in order to enable physical removing of mounted memory
sticks -- this is OK for fat-based sticks
ACTION=="add",KERNEL=="sda*", RUN+="/bin/mount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sda*", RUN+="bin/umount %k"
Is it possible that the umounting is not working because my program may still hold a handle to a file on the device ?
What is the best way to force a USB storage device to be always mounted to a specifc location? (Ex: /media/usb1)
mount
from a Udev rule because Udev tends to run in a private mount namespace, and because it won't work ifmount
starts a long-running process like FUSE.