On Di, 24.10.17 17:27, Jan Kundrát (jan.kund...@cesnet.cz) wrote: > I would like to mount one of two partitions to a common mount point based on > an option passed on the kernel's command line. I tried to implement this > with two cfg-A.mount and cfg-B.mount units with an appropriate > ConditionKernelCommandLine=... stanzas, but this did not work because a > .mount unit apparently needs to have a name which exactly matches its > mountpoint. I don't know how I can have two units with a different content > sharing the same unit name, though. > > Here's my cfg-A.mount, the other one was very similar: > > > [Unit] > > Description=Persistent configuration: slot A > > ConditionKernelCommandLine=rauc.slot=A > > DefaultDependencies=no > > Conflicts=umount.target > > Before=local-fs.target umount.target > > After=swap.target > > > > [Mount] > > What=/dev/mmcblk0p2 > > Where=/cfg > > Type=auto > > Options=relatime,nosuid,nodev > > In the end, I kinda-solved this by a custom oneshot service which simply > calls `mount` explicitly, but that's probably not a very systemd-ish > solution. > > How should I solve this elegantly?
My recommendation would be to generate the mount unit dynamicly using a "generator". A systemd unit file "generator" is a way how you can extend the unit dependency tree programatically with your own units, depending on foreign configuration. It's how /etc/fstab and sysvinit scripts are integrated into systemd's unit file tree, but configuration doesn't have to come from /etc, it could also come from /proc/cmdline or such. systemd-debug-generator is one standard generator we ship: depending on a kernel cmdline option it will pull in debug-shell.service. Your generator would be very similar to this. Our own generators are all written in C, but you can write generators in any language you like, including shell. Here's the documentation for this feature: https://www.freedesktop.org/software/systemd/man/systemd.generator.html Lennart -- Lennart Poettering, Red Hat _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel