How you create a systemd .mount file for bind mounts
One of the types of units that systemd supports is mount units (see
'man systemd.mount'). Normally you set up all your mounts with
/etc/fstab entries and you don't have to think about them, but
under some specialized circumstances you can wind up needing to
.mount service files for some mounts.
How to specify most filesystems is pretty straightforward, but it's
not quite clear how you specify Linux bind mounts.
Since I was just wrestling repeatedly with this
today, here is what you need to put in a systemd
.mount file to
get a bind mount:
[Mount] What=/some/old/dir Where=/the/new/dir Type=none Options=bind
This corresponds to the mount command '
mount --bind /some/old/dir
/the/new/dir' and an
/etc/fstab line of '
none bind'. Note that the type of the mount is
as you might expect. This works because current versions of
will accept arguments of '
-t none -o bind' as meaning 'do a bind
(I don't know if you can usefully add extra options to the
setting or if you'd need an actual script if you need to, eg, make
a bind mountpoint read-only. If you can do it in
can probably do it here.)
A fully functioning
.mount unit will generally have other stuff
as well. What I've wound up using on Fedora 20 (mostly copied from
[Unit] DefaultDependencies=no Conflicts=umount.target Before=local-fs.target umount.target [Mount] [[ .... whatever you need ...]] [Install] WantedBy=local-fs.target
Add additional dependencies, documentation, and so on as you need
or want them. For what it's worth, I've also had bind mount units
work without the three
[Unit] bits I have here.
Note that this assumes a 'local' filesystem, not a network one. If
you're dealing with a network filesystem or something depending on
one, you'll need to change bits of the targets (systemd documentation
Comments on this page:Written on 13 August 2014.