2

I just updated and installed a whole load of debian packages and now I am getting errors due to my particular fstab file config. I have 2 drives which I never mount simultaneously and which both have the same mount point (/etc/fstab snippet):

UUID=xxxx-xxxx /media/strontium vfat user,rw,exec,nofail 0 2                    
UUID=yyyy-yyyy /media/strontium vfat user,rw,exec,nofail 0 2

However, after the installations, systemd is complaining about this:

[518052.191024] systemd-fstab-generator[28811]: Failed to create mount unit file /run/systemd/generator/media-strontium.mount, as it already exists. Duplicate entry in /etc/fstab?

I actually don't want to use systemd to mount drives for me at all. I previously used sudo mount -a and this just went through my /etc/fstab file and mounted anything that was plugged in.

Is it possible to turn off the systemd mounting functionality so that I can mount my own drives manually as before?

4

I don't know anyway round this systemd restriction, as the mount point directory name is converted into a systemd filename. The simplest answer may be to remove the entries from the fstab and write a tiny script to do the mounts on demand:

#!/bin/bash
( mount -U xxxx-xxxx /media/strontium -t vfat -o rw,exec ||
  mount -U yyyy-yyyy /media/strontium -t vfat -o rw,exec
) && echo ok

Don't forget, after modifying /etc/fstab, to do a sudo systemctl daemon-reload to ensure systemd notices your changes.


If you want to keep the entries in /etc/fstab you could use make the second mount point a symbolic link to the first, eg ln -s /media/strontium /media/strontium2. When the mount is done the link is followed so it ends up on the directory as usual. You must add option noauto to both lines in this case, else systemd will get confused and immediately unmount what it thinks is the first entry.

Instead of a symbolic link you can instead use a real directory and then do a manual bind mount to mount that directory at the wanted place:

mount --bind /media/strontium2 /media/strontium

You must remember to umount this bind mount as well as the first mount.


In the past you could have added a udev rule to call mount explicitly when you see the UUID appear, eg in /etc/udev/rules.d/92-my.rules:

ACTION=="add", ENV{ID_FS_UUID}=="xxxx-xxxx", RUN+="/usr/bin/mount /dev/%k /media/strontium"

but this doesn't work with recent systemd's, as it runs udevd in a separate mount namespace, so although it does the mount, you cannot see it. I don't yet know the reason for this namespace, but you can in principle override this feature by creating a file /etc/systemd/system/systemd-udevd.service with the 2 lines

.include /usr/lib/systemd/system/systemd-udevd.service
MountFlags=shared 

If you want something that is still automatic, then an alternative is to monitor the events from udevd concerning block devices and do an explicit mount. For example, run permanently:

#!/bin/bash
# udevadm monitor outputs a stanza ending with a blank line
#  UDEV  [5291328.3] add  /devices/pci0000:00/.../usb3/..../block/sdd (block)
#  ACTION=add
#  DEVNAME=/dev/sdd
stdbuf -o L udevadm monitor -u -p -s 'block/disk' |
awk -F= '
$0~/^ACTION=/{ action = $2 }
$0~/^DEVNAME=/{ name = $2 }
$0~/^ID_FS_UUID=/{ uuid = $2 }
$0~/^$/{ if(action=="add" && (uuid=="xxxx-xxxx"||uuid=="yyyy-yyyy")
          system("sudo mount mount " name " /media/strontium -t vfat -o rw,exec")
         uuid=""
       }'
  • thanks for all the ideas! i won't mark as the correct answer just in case someone knows how to disable systemd's auto mount functionality and writes an answer for this. – mulllhausen Oct 22 '16 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.