My task is to have a custom mount point and for the mount itself to happen automatically. that is, the device is connected, a folder with its name is created in some place (/mnt/usb/{name}) and the data is mounted there. when the device is disconnected, the folder is unmounted and deleted
Wrote a udev rule
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[b-z][0-9]", ENV{ID_BUS}=="usb", \
ENV{ID_TYPE}=="disk", ENV{ID_FS_USAGE}=="filesystem", \
RUN+="/bin/mount -w -o umask=0000,uid=0,gid=0 /dev/%k /mnt/usb_drives"
ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sd[b-z][0-9]", ENV{ID_BUS}=="usb", \
ENV{ID_TYPE}=="disk", ENV{ID_FS_USAGE}=="filesystem", RUN+="/bin/umount /mnt/usb_drives"
I look at df -h and I don't see my mounted device there, I tried writing a rule via pmount and still no result. Nothing is written in the logs, or it gives an error with a return value of 1
I tried to write commands in scripts, but as I understand it, the problem is that HE DOESN'T WANT TO RUN THROUGH THE ROOT USER. HOW IS THIS??
SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", \
ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", \
ENV{UDISKS_AUTO}="0"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", \
ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", \
RUN+="sh /etc/udev/rules.d/mount-usb.sh %k"
#!/usr/bin/sudo bash
sleep 5
NAME_DEV=$1
mkdir "/mnt/usb/$NAME_DEV"
sudo /bin/mount "/dev/$NAME_DEV" "/mnt/usb/$NAME_DEV"
The device folder is created but the data is not mounted in it
EDIT
Changed the rule and the script, and also moved the script to /usr/bin/
/usr/bin/mount-usb.sh
#!/usr/bin/sudo bash
NAME_DEV=$1
/usr/bin/pmount --umask=000 -s -w "/dev/$NAME_DEV"
/etc/udev/rules.d/99-usb-mount.rules
SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", ENV{UDISKS_AUTO}="0"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", RUN+="/usr/bin/mount-usb.sh %k"
After connecting a USB flash drive, a folder is created in /media, but data is still not mounted in it
NEW EDIT
SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", \
ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", \
ENV{UDISKS_AUTO}="0"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", \
ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", \
RUN+="mkdir /mnt/usb/%k && systemd-mount --no-block -o umask=000,rw /dev/%k /mnt/usb/%k"
Returns an error as if it were access rights...
systemd-udevd[3099]: sdb1: Process 'mkdir /mnt/usb/sdb1 && systemd-mount --no-block -o umask=000,rw /dev/sdb1 /mnt/usb/sdb1' failed with exit code 1.
TRYING WITH SCRIPT
/usr/bin/mount-usb.sh
#!/usr/bin/sudo bash
NAME_DEV=$1
MOUNT_POINT="/mnt/usb/${NAME_DEV}"
mkdir "${MOUNT_POINT}"
/usr/bin/mount -o umask=000,rw "/dev/${NAME_DEV}" "${MOUNT_POINT}"
/etc/udev/rules.d/99-usb-mount.rules
SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", \
ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", \
ENV{UDISKS_AUTO}="0"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", \
ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", \
RUN+="/usr/bin/mount-usb.sh %k"
The script runs, but the device still doesn't mount in the folder I create. the folder I mount in (/mnt/usb) is set to chmod 777.
Folder /mnt/usb/sdb1 was created, but there is no data from the usb device in it
richstog-VirtualBox sudo[4342]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/bash /usr/bin/mount-usb.sh sdb1
udevadm trigger
?/dev
until that rule finishes executing ... You can't mount it that way. Please see similar issue discussed here: Different behaviour of bash script in udev