What happens when I try to mount a USB drive with systemd?

What happens when I try to mount a USB drive with systemd?

The old rules almost still work – the mount point gets created and the drive is mounted fine, but after a few seconds systemd is doing something that breaks the mount, so subsequent access attempts result in “Transport endpoint is not connected” errors. Manually mounting the drive via the command line works fine.

How do I mount a USB drive with udev?

The key is to add a systemd unit service between udev and a mounting script. (For the record, I was not able to get this working using udisks2 (via something like udisksctl mount -b /dev/sdb1) called either directly from a udev rule or from a systemd unit file.

How does Udisks2 take care of Mount points?

Unfortunate, since udisks2 could take care of all the mount point messyness…) The heavy lifting is done by a shell script, which takes care of creating and removing mount points, and mounting and unmounting the drives.

Can a command line be used to mount a hard drive?

Manually mounting the drive via the command line works fine. So does letting a file manager (thunar and thunar-volman, which in turn uses udisks2). But those are not viable options – these systems mostly run headless, so thunar isn’t normally running.

How is the script called by a systemd unit file?

The script, in turn, is called by a systemd unit file. We use the “@” filename syntax so we can pass the device name as an argument. Finally, some udev rules start and stop the systemd unit service on hotplug/unplug:

How to run a script when a specific flash drive is?

Create a new udev rules file in /etc/udev/rules.d/ via sudoedit /etc/udev/rules.d/100-mount-videos.rules and plonk a new rule in there like this: Note how I used the ID from lsusb. Then you just need to write the script to do the work. A simple mount command should work.

Is there a way to make usbmount work again?

Therefor if you want to make usbmount work again, the already given configuration syntax is right. But you should place it like this. Create a configuration container directory /etc/systemd/system/systemd-udevd.service.d. Create an own confugration file (that will overwrite the package configuration).