Hi Seth,


On Thu, May 16, 2019 at 3:23 AM Seth Kenlon <skenlon@redhat.com> wrote:
Here's what I use for my automated backup script (see
https://gitlab.com/slackermedia/attachup for context):

If you adapt this, you'll need to update the path (I use /media),
you'll need to update the UUID, and you'll probably need to verify
that your drive has a label, because this rule uses the UUID and label
to identify the drive.

I save this as 80.local-rules in /etc/udev/rules.d
Supposedly you can do a `udevadm control reload` to force the rules to
be reloaded, but I usually reboot just to make sure udev is on top of
its game.

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get label or create one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# mount
ACTION=="add", ENV{mount_options}="relatime"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs",
ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l
/media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
#mount
ACTION=="add",ENV{ID_FS_UUID}=="165f84bc-1d70-47a4-9fdc-7a588fa457c4",RUN+="/bin/mkdir
-p /media/%E{dir_name}",RUN+="/bin/mount -o $env{mount_options}
/dev/%k /media/%E{dir_name}",MODE="0770",GROUP="users"

I tried with your udev rule but no luck.


[root@hanthana ~]# cat /etc/udev/rules.d/81-hnt-usb-rule.rules
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get label or create one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="backup-%k"
# mount
ACTION=="add", ENV{mount_options}="relatime"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs|ext4", ENV{mount_options}="$env{mount_options},utf8,umask=002"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
#mount
ACTION=="add",ENV{ID_FS_UUID}=="7720-13E1",RUN+="/bin/mkdir -p /media/%E{dir_name}",RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}",MODE="0770"
[root@hanthana ~]#
[root@hanthana ~]#
[root@hanthana ~]# udevadm control --reload
[root@hanthana ~]#

I noticed that udev rule create the given directory but it won't mount the device under given directory but usual direcotry /run/meda/<user>/<LABEL>.
[root@hanthana ~]# ls /media/backup/
[root@hanthana ~]#
[root@hanthana ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        16G  5.5G  9.7G  37% /run/media/danishka/LIVE


I did test the rule.

run: '/bin/mkdir -p /media/backup'
run: '/bin/mount -o relatime,utf8,umask=002 /dev/sdb1 /media/backup'
Unload module index
Unloaded link configuration context.