Skip to content

Allow setting network configuration via network-scripts #1334

Open
@pjgeorg

Description

@pjgeorg

Not sure this is indeed a feature request / issue /..., but probably more like a request for comments how one could handle my current usecase:

Instead of specifying network options on the cmdline I add network-scripts to initrd. I mainly use this setup to boot up clusters of diskless nodes. I'm still running CentOS 8, however I'm currently evaluating possible updates.

The only network related option I specify on the command line is: bootdev=ib0
For CentOS 8 I added the following patches to make it work:

--- usr/lib/dracut/modules.d/35network-manager/nm-lib.sh
+++ usr/lib/dracut/modules.d/35network-manager/nm-lib.sh
@@ -6,6 +6,7 @@
 {
     rm -f /run/NetworkManager/system-connections/*
     /usr/libexec/nm-initrd-generator -- $(getcmdline)
+    rm -f /run/NetworkManager/system-connections/*
 
     if getargbool 0 rd.neednet; then
         for i in /usr/lib/NetworkManager/system-connections/* \
--- usr/lib/dracut/modules.d/35network-manager/nm-run.sh
+++ usr/lib/dracut/modules.d/35network-manager/nm-run.sh
@@ -17,11 +17,14 @@
   break
 done
 
+BOOTDEV=$(getarg bootdev=)
+
 for _i in /sys/class/net/*
 do
     state=/run/NetworkManager/devices/$(cat $_i/ifindex)
     grep -q connection-uuid= $state 2>/dev/null || continue
     ifname=${_i##*/}
+    [ -n "$BOOTDEV" ] && [ "$BOOTDEV" = "$ifname" ] || continue
     sed -n 's/root-path/new_root_path/p;s/next-server/new_next_server/p' <$state >/tmp/dhclient.$ifname.dhcpopts
     source_hook initqueue/online $ifname
     /sbin/netroot $ifname

The first patch is required as nm-initrd-generator creates a default_connection.nmconnection, which is for an interface already handled by bundled network-scripts. Afaik with a more up to date NetworkManager this file is now called $bootdev.nmconnection. Afaik this is due to the following upstream commit and me specifying bootdev= on the command line: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/25a2b6e14ff525be9838f4b0d90680e49b145f2b
However, issue is still the same: This interface is already taken care of by an network-script. I want nm-initrd-generator to simply create no new connections. Hence one might probably just not run it at all.

The second part of the patch (together with specifying bootdev= on the command line) ensures that only this particular interface is online to then mount the root directory using NFS over this interface with no possible interference of any other interface.

I'm not a 100% sure yet how this interacts with this upstream commit: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/f114e16fddf854d72a8b08318359569cd83245e3

I do know bootdev= was not meant for this particular use case, but it seemed suitable to me to "misuse" it for this purpose.

With the patches mentioned above this setup currently works as I need it to. However I wanted to ask whether this is a good approach, I'm simply missing some feature of dracut / NetworkManager that allows me to do this without any patches, or this approach (using network-scripts only) is simply not supported upstream?

Thanks for any comments / help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIssue adding new functionalitynetwork-managerIssues related to the network-manager module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions