Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Last active June 11, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palaniraja/73c21924d795f5cede1d0c753a052f74 to your computer and use it in GitHub Desktop.
Save palaniraja/73c21924d795f5cede1d0c753a052f74 to your computer and use it in GitHub Desktop.

Did not work for me with raspberry pi

/etc/udev/rules.d/usbstick.rules

ACTION=="add", KERNEL=="sd[a-z][0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}="usbstick-handler@%k"

/usr/local/bin/automount

#!/bin/bash

PART=$1
FS_LABEL=`lsblk -o name,label | grep ${PART} | awk '{print $2}'`
if [ -z ${FS_LABEL} ]
then
  /usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${PART}
else
  /usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${FS_LABEL}_${PART}
fi
sudo chmod +x /usr/local/bin/automount

/lib/systemd/system/usbstick-handler@.service

[Unit]
Description=Mount USB sticks
BindsTo=dev-%i.device
After=dev-%i.device

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/automount %I
ExecStop=/usr/bin/pumount /dev/%I
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment