Skip to content

Instantly share code, notes, and snippets.

@syntaxhacker
Last active July 13, 2026 19:41
Show Gist options
  • Select an option

  • Save syntaxhacker/57d4ce7a047936126263f6b8255a059c to your computer and use it in GitHub Desktop.

Select an option

Save syntaxhacker/57d4ce7a047936126263f6b8255a059c to your computer and use it in GitHub Desktop.
Lenovo USB auto-mount with systemd-mount (udev)
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="61F4-EB04", RUN+="/usr/bin/systemd-mount --no-block --automount=yes --options=defaults,uid=1000,gid=1000 $devnode /mnt/usb"
ACTION=="remove", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="61F4-EB04", RUN+="/usr/bin/systemd-mount --umount $devnode"

Lenovo USB Auto-Mount (udev + systemd-mount)

Auto-mounts Lenovo USB drive at /mnt/usb on plug-in using systemd-mount.

Files

File Location Purpose
99-usb-lenovo.rules /etc/udev/rules.d/99-usb-lenovo.rules udev rule - runs systemd-mount on plug-in

How It Works

USB PLUGGED IN
       │
       ▼
  KERNEL: detects USB → /dev/sdX1, UUID 61F4-EB04 (exFAT)
       │
       ▼
  UDEV: matches rule → runs systemd-mount
       │
       ▼
  systemd-mount: creates automount at /mnt/usb
       │
       ▼
  On first access to /mnt/usb → filesystem mounts automatically

Why systemd-mount?

Approach Result
mount in udev RUN ❌ Breaks — udev sandbox, mounts invisible to system
SYSTEMD_WANTS + fstab ❌ Fragile — dependency conflicts, boot failures
systemd-mount in udev RUN ✅ Works — proper systemd integration, no conflicts

Installation

# 1. Create mount point
sudo mkdir -p /mnt/usb

# 2. Copy udev rule
sudo cp 99-usb-lenovo.rules /etc/udev/rules.d/

# 3. Remove any conflicting fstab entry
sudo sed -i '/61F4-EB04/d' /etc/fstab

# 4. Reload
sudo udevadm control --reload-rules
sudo systemctl daemon-reload

# 5. Plug in USB — it auto-mounts at /mnt/usb

USB Removal

The remove rule runs systemd-mount --umount which cleanly unmounts and removes the automount unit.

Troubleshooting

# Check if device is detected
lsusb | grep Lenovo

# Check block devices
lsblk

# Check mount
mount | grep /mnt/usb

# Test systemd-mount manually
sudo systemd-mount --no-block --automount=yes --options=defaults,uid=1000,gid=1000 /dev/sdX1 /mnt/usb
# No fstab entry needed — udev + systemd-mount handles everything.
# Remove any existing fstab entry for this UUID to avoid conflicts:
# sudo sed -i '/61F4-EB04/d' /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment