Skip to content

Instantly share code, notes, and snippets.

@scresante
Last active May 10, 2019 19:23
Show Gist options
  • Save scresante/4b98a165c8b52176d461c0cdae1a7df6 to your computer and use it in GitHub Desktop.
Save scresante/4b98a165c8b52176d461c0cdae1a7df6 to your computer and use it in GitHub Desktop.
automount rule for systemd + udev and CPX boards
KERNEL!="sd[a-z][0-9]", GOTO="cpx_by_sn_automount_end"
ATTRS{vendor}=="Adafruit", ENV{vendor}="$attr{vendor}"
ATTRS{serial}=="*", ENV{serial}="$attr{serial}"
#import FS infos
## this imports ID_FS_UUID
IMPORT{program}="/usr/bin/blkid -o udev -p %N"
IMPORT{program}="/bin/sh -c \"/usr/bin/echo serial=%E{serial} | /usr/bin/cut -c1-12\""
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}-%E{serial}"
ENV{dir_name}=="", ENV{dir_name}="%E{ID_FS_LABEL_FATBOOT}-%E{serial}"
ACTION=="add", ENV{mount_options}="uid=1000,flush,sync"
# Mount the device
ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{vendor}=="Adafruit", RUN+="/usr/bin/systemd-mount --no-block --automount=yes --collect --owner=1000 --options=%E{mount_options} /dev/%k /media/%E{dir_name}"
ACTION=="remove", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{vendor}=="Adafruit", RUN+="/usr/bin/systemd-mount --no-block --automount=yes --collect -u /dev/%k /media/%E{dir_name}"
LABEL="cpx_by_sn_automount_end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment