I want to mount a drive with a specific label automatically everytime it gets pugged-in. I do not want to use any other tool than systemd
as other units depend on the mount and must be started automatically.
What I have got so far:
/lib/systemd/system/mount-camera.mount
[Unit]
Description=the camera SDCard
StopWhenUnneeded=true
Before=copy-camera.service
[Mount]
What=LABEL=CAMERA
Where=/mount/camera
Type=vfat
[Install]
WantedBy=multi-user.target
/lib/systemd/system/mount-camera.automount
[Unit]
Description=camera SDCard
[Automount]
Where=/mount/camera
[Install]
WantedBy=multi-user.target
This does successfully mount the drive if I cd
into the mountpoint. However I want the drive to be mounted just because I insert it because there is a service that is started by the mount unit.
Is it possible to achieve this using systemd? If yes: How?
If it is impossible: is there a way I could do it with very few extra steps?
Note
I know that I could add a timer that cd
s into the mountpoint every x seconds - but this is note really elegant, is it?
udev
does the mounting andsystemd
monitorsudev
automatically I think.udev
rule?mount
unit. See my answer below.