[systemd-devel] elegant way to use a single mount unit file for multiple paths

Marcel Partap mpartap at gmx.net
Wed Jan 22 17:59:20 UTC 2020


Salut,
for our live debian USB stick distro for students ( https://github.com/fsfw-dresden/usb-live-linux ), we want to minimize on flash writes by putting several paths into a tmpfs overlay. So there is a pre-overlay at .service with

> [Unit]
> Description=Prepare writable overlay on %f
> DefaultDependencies=no
> RequiresMountsFor=/run
>
> [Service]
> Type=oneshot
> ExecStart=/bin/mkdir -p '/run%f'
> ExecStart=/bin/mount -t tmpfs -o noatime tmpfs '/run%f'
> ExecStart=/bin/mkdir -p '/run%f/work' '/run%f/rw'

and f.e. a var-lib-apt-lists.mount with
> [Unit]
> Description=tmpfs overlay of %f
> Conflicts=umount.target
> Wants=pre-overlay@%p.service
> After=pre-overlay@%p.service
>
> [Mount]
> What=overlay
> Type=overlay
> Where=%f
> Options=lowerdir=%f,upperdir=/run%f/rw,workdir=/run%f/work
>
> [Install]
> WantedBy=local-fs.target

Currently, the file is just cloned for multiple paths, which is working but not very elegant. I tried changing it into an instanced unit file tmpfs-overlay at .mount, which did not work ("Unit type mount cannot be templated" in journal only, nothing from systemd-analyze verify or the systemd.mount man page).. Neither did calling the file tmpfs-overlay.mount.unit and symlinking to it as var-lib-apt-lists.mount, var-cache-apt.mount etc.

So what would be a more elegant way to not have multiple copies of the very same file?

Best Regards,
#marcel


More information about the systemd-devel mailing list