TransWikia.com

Some RUN-Commands in UDEV-Rule are ignored

Unix & Linux Asked by niels on December 6, 2021

Running a raspberry pi and update to raspbian buster. With Jessie the same file works fine.
I used the following udev-rule:

# Idea from https://www.axllent.org/docs/view/auto-mounting-usb-storage/
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
# Mount the device
ACTION=="add", RUN+="/bin/date >> /tmp/xx"
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}",  RUN+="/bin/date >> /tmp/xx"
# 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"

If I add my mp3-player a directory /media/MP3_INTENSO will be created and if I remove it, the directory will be deleted.

This only happens if I have the rule-file. So it’s definitely an effect of the file.

I tried udevadm monitor and find the expected:
UDEV [2378.210993] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1 (block)

Running udevadm test /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1 then returns:

dir_name=MP3_INTENSO
mount_options=relatime,utf8,gid=100,umask=002
TAGS=:systemd:
USEC_INITIALIZED=2377859838
run: '/bin/date >> /tmp/xx'
run: '/bin/mkdir -p /media/MP3_INTENSO'
run: '/bin/mount -o relatime,utf8,gid=100,umask=002 /dev/sda1 /media/MP3_INTENSO'
run: '/bin/date >> /tmp/xx'
Unload module index
Unloaded link configuration context.

It’s look like expected. I can successful run each command in the command line.
However I never found an entry in /tmp/xx if I only plugin the device and the device is never mounted.

I didn’t find anything in /var/log/messages or dmesg.

What’s wrong and what can I do for further analyse?

One Answer

For further analysis it's usefull to edit /etc/udev/udev.conf and add udev_log=debug. The restart udev with systemctl restart udev.

With this you will get the following information:

'/bin/date >> /tmp/xx'(err) '/bin/date: extra operand '/tmp/xx''
'/bin/date >> /tmp/xx'(err) 'Try '/bin/date --help' for more information.'

So it seems that the ">>" doesn't work. A simple /usr/local/bin/log.sh can do the work. After that I figured out that the mp3-player is successful mounted. The interesting question now is who is unmounting the device very quickly, but this is an other problem.

An explanation why the mount fail can be found at archlinux-wiki.

Answered by niels on December 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP