Skip to content

Instantly share code, notes, and snippets.

@sant123
Created April 9, 2024 00:54
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 sant123/6faeac0045e414dc6fdb923052975543 to your computer and use it in GitHub Desktop.
Save sant123/6faeac0045e414dc6fdb923052975543 to your computer and use it in GitHub Desktop.
Automount usb devices with systemd and udisks2
# Mount usb devices with systemd and udisks2
ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1"
ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem",\
RUN+="/usr/bin/systemctl --no-block start automount-usb@%k.service"
[Unit]
Description=Automount USB devices
[Service]
Type=oneshot
ExecStart=/usr/bin/udisksctl mount -b /dev/%i
# Put the contents of 98-automount-usb.rules under /etc/udev/rules.d -> /etc/udev/rules.d/98-automount-usb.rules
# Put the contents of automount-usb@.service under /etc/systemd/system -> /etc/systemd/system/automount-usb@.service
# In shell execute the following commands
sudo udevadm control --reload
sudo udevadm trigger
sudo systemctl daemon-reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment