Hi, I’ve set up a basic file server running samba over dietpi. The standard mount points work perfectly and the use of dietpi-drive_manger makes mounting and unmounting a drive a breeze.
However, I want the system to auto-mount any USB device and remove it from the path even if removed insecurely. I have searched the forum regarding this and did find this script that to most part, works well.
The issues I’m facing are:
- I keep getting the following error message while navigating the directories on Windows 11. Usually, once a directory is entered, or exited.
- I cannot write to the drive.
I have set “path = /ZFSpoolMirrored/public/automount/” in smb.conf. This is the only variable changed in that file.
The script in use is below.
## https://www.lytning.org/blog/2023/linux_01_automount_usb.html
KERNEL!="sd*", GOTO="media_by_label_auto_mount_end"
ENV{ID_TYPE}!="disk", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_TYPE}=="", GOTO="media_by_label_auto_mount_end"
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="%E{ID_FS_UUID}"
# FAT* / exFAT / NTFS don't support Unix directory permissions, so set the mount directory to `nobody:nogroup` and make R+W for those users, read-only for everyone else
ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="vfat|exfat|ntfs", RUN{program}+="/usr/bin/systemd-mount --owner=nobody --options=rw,umask=002 --no-block --automount=yes --collect /dev/%k /ZFSpoolMirrored/public/automount/%E{dir_name}"
# Most other common filesystem types do support Unix directory permissions, so set the mount directory to `nobody:users` with 755 permissions
ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", ENV{ID_FS_TYPE}!="vfat", ENV{ID_FS_TYPE}!="exfat", ENV{ID_FS_TYPE}!="ntfs", RUN{program}+="/usr/bin/systemd-mount --options=X-mount.mode=1775,X-mount.owner=nobody,X-mount.group=users --no-block --automount=yes --collect /dev/%k /ZFSpoolMirrored/public/automount/%E{dir_name}"
# Clean up after removal
ACTION=="remove", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", ENV{dir_name}!="", RUN{program}+="/usr/bin/systemd-umount /ZFSpoolMirrored/public/automount/%E{dir_name}", RUN{program}+="/bin/rmdir /ZFSpoolMirrored/public/automount/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
Please help me resolve this issue. My understanding of Linux is elementary.
EDIT: updated information.
