1

I'm trying to leverage netplan's ability to override configurations with lexicographically later files, but when these files come from another mount point, the whole thing fails.

I've created a virtual machine with a few interfaces, and those are configured with sensible defaults using files like /etc/netplan/01-primary.yaml and /etc/netplan/02-local.yaml (which basically say "use dhcp"). That part works well. However what I'm trying to achieve is the ability to override the settings using an optional drive mount.

For this I have added a mount point to /etc/fstab with the following contents:

/dev/vdb /mnt/config ext4 defaults,nofail,x-systemd.device-timeout=10,x-systemd.before=systemd-networkd.service 0 0

And then I added symlinks to /etc/netplan that point to new config files, such as ln -s /mnt/config/netplan/11-primary.yaml /etc/netplan/11-primary.yaml.

My first problem was that if the drive is not present and mounted, the whole netplan generate fails at boot time and I am left without any interfaces (I have issued a bug report about missing symlinks to netplan). I managed to overcome this issue by simply creating the necessary directory structure with empty files in /mnt/config. However even with the drive present, netplan does not see these files at boot time. If I run netplan generate and netplan apply after boot, all the interfaces get configured correctly.

I have tried many different x-systemd.before targets but none of them work. Is there any way to get this working correctly? The config mount should be optional so that the virtual machine can be booted without one.

0

1 Answer 1

0

I have been struggling with this today and I've identified two main solutions for it so far:

  1. Use cron to run netplan apply on @reboot but there seemed to be way too many caveats attached to it.
  2. Create a systemd unit to run netplan apply after the mount.

I choose option 2 and here is the systemd unit file:

[Unit]
Description=Execute netplan apply after mount
After=multi-user.target mnt.mount

[Service]
Type=oneshot
ExecStart=/bin/sh -c "netplan apply"

[Install]
WantedBy=multi-user.target

Save it under /etc/systemd/system/network-after-mount.service and go systemctl enable network-after-mount. Reboot to test.

In our case it's an internal USB stick which gets mounted under /mnt/ containing the extra netplan config files. If you mount your drive under another path the generated systemd mount unit will be named differently. You can list the mount units with

systemctl list-units --type=mount

and identify which is the correct one to target.

1
  • This additional service sounds like it might work, as long as all other dependencies are in place. I too tried using the @reboot cron, but as there are other services that are dependent on network, this was not a very good idea. I will try and see if the additional service might do the trick. Thanks! Dec 12, 2018 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .