Sources:
- https://raspberrypi.stackexchange.com/a/66324
- https://raspberrypi.stackexchange.com/a/72518
- https://github.com/avanc/mopidy-vintage/wiki/Automount-USB-sticks
So, I found a solution that works quite well. Big thanks to avanc and his udev rule that makes this possible. I also modified it so that it could mount up to 4 flash drives at the same time (it can be increased if needed).
- Install pmount if not installed
sudo apt-get install pmount
. - This script mounts drives to /media/usb*, so make sure those folders aren't occupied. If you want a cleaner look, don't create any folders.
- Create file
/etc/udev/rules.d/usbstick.rules
- Insert:
ACTION=="add", KERNEL=="sd[a-z][0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}="usbstick-handler@%k"
- Save and close.
- Create file
/lib/systemd/system/[email protected]
- Insert:
[Unit]
Description=Mount USB sticks
BindsTo=dev-%i.device
After=dev-%i.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/automount %I
ExecStop=/usr/bin/pumount /dev/%I
- Save and close.
- Create file
/usr/local/bin/automount
- Insert:
#!/bin/bash
PART=$1
FS_LABEL=`lsblk -o name,label | grep ${PART} | awk '{print $2}'`
if [ -z ${FS_LABEL} ]
then
/usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${PART}
else
/usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${FS_LABEL}_${PART}
fi
- Save and close.
- Give the permitions
sudo chmod +x /usr/local/bin/automount
.
- Reboot your RPi and test.
- You can change pmount parameters, but these allow anyone r/w access to usb.
- The amount of mountpoints can be changed.
- Thanks to avanc for his udev rule and service.
[Global]
vol preset = default_for_all_vol
hostname = RaspberryPi
log file = /var/log/netatalk.log
log level = default:error
uam list = uams_dhx.so, uams_dhx2.so
save password = yes
keep sessions = yes
mimic model = Xserve
[default_for_all_vol]
file perm = 0665
directory perm = 0775
valid users = @pi
;[Homes]
;path = library
;basedir regex = /home
;home name = "Library"
[Library]
time machine = no
path = /media