I am attempting to rename the network interfaces on a device using udev rules. I know that this can be done by modifying the config.json but we would like for it to be done at runtime.
I have created a rule /etc/udev/rules.d/70-persistent-net.rules:
If I try to run the udev rules using udevadm control --reload-rules && udevadm trigger the rule errors out because the resource is being busy. In order to fix this, I can take the interface down using ip link set down enp6s0 and then running the udevadm command works and the interface is renamed.
The issue comes with that this rule is not persistent and should take affect on every reboot but does not seem to work. I am looking for any help or suggestions on how to get this to work.
Our thought process is best described by one of the balena engineers in his own words:
I unfortunately don’t see much of a clean way to achieve your goal using udev rules from a container. As far as I understand, what is happening is:
The rule doesn’t trigger at boot time because the “add” event is triggered earlier in the startup process, before the container has a chance to run.
I did a quick search and I don’t think network interfaces generate “change” events, so this wouldn’t help either.
Running udevadm trigger effectively replay the events and give the rules another change to trigger, but (as you noticed) the rule will fail if the network interface is already up.
I imagine it would be technically possible to run some script on the container that would circumvent each of these obstacles, but in my opinion such solution would be quite convoluted and brittle (because we’d be essentially going against the way these things were meant to be used).
I hope the exchange is able to help others as well.