1

I have the following mount and automount units enabled for my external USB drive.

Mount Unit:

[Unit]
Description=Time Machine Drive Mount Service

[Mount]
What=/dev/disk/by-uuid/some-uuid
Where=/media/timemachine
Type=hfsplus

[Install]
WantedBy=multi-user.target

Automount Unit:

[Unit]
Description=Time Machine Drive Automount Service

[Automount]
Where=/media/timemachine

[Install]
WantedBy=multi-user.target

How do I tell systemd to bind the mount point to another directory every time I plug in the drive?

303
  • 145
  • 7
  • Did you see this Q&A - https://unix.stackexchange.com/questions/339561/bind-usb-drive-to-home-directory-on-demand. Seems to make your Q a dup. – slm Jul 24 '18 at 18:21
  • I did, but I'm not even sure what his question is. Furthermore I'm primarily interested in doing it with systemd. – 303 Jul 24 '18 at 18:25
  • See my A'er, doesn't seem possible, unless I'm misunderstanding things. – slm Jul 24 '18 at 18:25
  • Read this: https://unix.stackexchange.com/questions/65891/how-to-execute-a-shellscript-when-i-plug-in-a-usb-device – Bob Jul 24 '18 at 18:54

1 Answers1

1

This issue for the upstream project systemd would seem to indicate that what you're trying to do is not possible, and they aren't going to add it, mainly due to limitations with how the kernel works.

excerpt

please note that bind mounts after they have been made are entirely independent entry points to the same file system than the original mount used to create them. This means, after creating /opt/oh as bind mounts the fact that /mnt/sda is on an automount point is entirely irrelevant for its lifecycle: the new bind mounts point directly to the effective file system, they lose any automount magic. And that's a kernel design choice and is nothing systemd can do anything about it.

Sorry, but systemd can't do what you want to do, because the kernel simply doesn't work that way!

sorry!

At any rate, you're left with alternative methods, one of which is described in this U&L Q&A titled: Bind USB drive to home directory on demand.

slm
  • 369,824