From 08bdadbf315cced437385228b2434a02a19090e4 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 30 Aug 2018 16:44:22 +0200 Subject: [PATCH] network-manager: add module --- dracut.spec | 1 + modules.d/35network-manager/module-setup.sh | 52 +++++++++++++++++++++++++++++ modules.d/35network-manager/nm-config.sh | 3 ++ modules.d/35network-manager/nm-run.sh | 16 +++++++++ modules.d/40network/module-setup.sh | 7 +++- 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/dracut.spec b/dracut.spec index f6486d50..b6099824 100644 --- a/dracut.spec +++ b/dracut.spec @@ -419,6 +419,7 @@ install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kerne %files network %{dracutlibdir}/modules.d/02systemd-networkd +%{dracutlibdir}/modules.d/35network-manager %{dracutlibdir}/modules.d/35network-legacy %{dracutlibdir}/modules.d/40network %{dracutlibdir}/modules.d/45ifcfg diff --git a/modules.d/35network-manager/module-setup.sh b/modules.d/35network-manager/module-setup.sh new file mode 100755 index 00000000..62aba3c6 --- /dev/null +++ b/modules.d/35network-manager/module-setup.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# called by dracut +check() { + local _program + + require_binaries sed grep || return 1 + + # do not add this module by default + return 255 +} + +# called by dracut +depends() { + return 0 +} + +# called by dracut +installkernel() { + return 0 +} + +# called by dracut +install() { + local _nm_version + + _nm_version=$(NetworkManager --version) + + inst_multiple sed grep + + inst NetworkManager + inst /usr/libexec/nm-initrd-generator + inst_multiple -o teamd dhclient + inst_hook cmdline 99 "$moddir/nm-config.sh" + inst_hook initqueue/settled 99 "$moddir/nm-run.sh" + inst_rules 85-nm-unmanaged.rules + inst_libdir_file "NetworkManager/$_nm_version/libnm-device-plugin-team.so" + + if [[ -x "$initdir/usr/sbin/dhclient" ]]; then + inst /usr/libexec/nm-dhcp-helper + elif ! [[ -e "$initdir/etc/machine-id" ]]; then + # The internal DHCP client silently fails if we + # have no machine-id + systemd-machine-id-setup --root="$initdir" + fi + + # We don't install the ifcfg files from the host automatically. + # But if the user chooses to include them, we pull in the machinery to read them. + if ! [[ -d "$initdir/etc/sysconfig/network-scripts" ]]; then + inst_libdir_file "NetworkManager/$_nm_version/libnm-settings-plugin-ifcfg-rh.so" + fi +} diff --git a/modules.d/35network-manager/nm-config.sh b/modules.d/35network-manager/nm-config.sh new file mode 100755 index 00000000..1339ebe7 --- /dev/null +++ b/modules.d/35network-manager/nm-config.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/usr/libexec/nm-initrd-generator -- $(getcmdline) diff --git a/modules.d/35network-manager/nm-run.sh b/modules.d/35network-manager/nm-run.sh new file mode 100755 index 00000000..f6defa99 --- /dev/null +++ b/modules.d/35network-manager/nm-run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then + /usr/sbin/NetworkManager --configure-and-quit=initrd --debug --log-level=trace +else + /usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon +fi + +for _i in /sys/class/net/*/ +do + state=/run/NetworkManager/devices/$(cat $_i/ifindex) + grep -q managed=true $state 2>/dev/null || continue + ifname=$(basename $_i) + sed -n 's/root-path/new_root_path/p' <$state >/tmp/dhclient.$ifname.dhcpopts + /sbin/netroot $ifname +done diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh index fbd43925..57c0a45e 100755 --- a/modules.d/40network/module-setup.sh +++ b/modules.d/40network/module-setup.sh @@ -2,7 +2,12 @@ # called by dracut depends() { - echo "network-legacy" + echo -n "kernel-network-modules " + if ! dracut_module_included "network-legacy" && [ -x "/usr/libexec/nm-initrd-generator" ] ; then + echo "network-manager" + else + echo "network-legacy" + fi return 0 }