From a6e07124f6bb9cb8f289471b19d8c4c37d7cfa05 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Wed, 14 Jun 2023 21:43:51 -0500 Subject: [PATCH] dracut-sshd-networkmanager subpackage 99sshd-auto-networkmanager adjusts nm-initrd.service to run for dracut-sshd. - If config is lacking auto DHCP ethernet in the same manner as rootfs NetworkManager. - Clean network teardown prior to switchroot avoids conflicts and gives OS full control. - Settings could be overriden by copying ifcfg or nmconnection settings into the initrd. Fixes: Issues #63 #68 Signed-off-by: Warren Togami --- 99sshd-networkmanager/module-setup.sh | 26 ++++++++++++++++++++++++++ dracut-sshd.spec | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 99sshd-networkmanager/module-setup.sh diff --git a/99sshd-networkmanager/module-setup.sh b/99sshd-networkmanager/module-setup.sh new file mode 100755 index 0000000..77be708 --- /dev/null +++ b/99sshd-networkmanager/module-setup.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# 2023, Warren Togami +# SPDX-License-Identifier: GPL-3.0-or-later + +# called by dracut +check() { + require_binaries sshd || return 1 + # 0 enables by default, 255 only on request + return 0 +} + +# called by dracut +depends() { + return 0 +} + +# called by dracut +install() { + # allow NetworkManager to auto configure "Wired connection #" DHCP connections for Ethernet interfaces + rm -f "$initdir/usr/lib/NetworkManager/conf.d/initrd-no-auto-default.conf" + + # tell Networkmanager to run + echo "rd.neednet" >> "${initdir}/etc/cmdline.d/50neednet.conf" + return 0 +} diff --git a/dracut-sshd.spec b/dracut-sshd.spec index 49c6b54..d70a081 100644 --- a/dracut-sshd.spec +++ b/dracut-sshd.spec @@ -20,6 +20,21 @@ initramfs. It allows for remote unlocking of a fully encrypted root filesystem and remote access to the Dracut emergency shell (i.e. early userspace). +%package networkmanager +Summary: Enables NetworkManager for sshd during initramfs +Requires: dracut-sshd +Requires: NetworkManager + +%description networkmanager +This module enables dracut network-manager settings for dracut-sshd. + +- If no configuration is provided it uses DHCP to bring up ethernet + in the same manner as rootfs NetworkManager. +- Cleanly tears down networking prior to switchroot to avoid conflicts + thereby allowing the OS full control of networking config. +- Network settings could be overriden by copying ifcfg or nmconnection + settings into the initrd. e.g. static IP's + %prep {{{ git_dir_setup_macro }}} @@ -30,6 +45,7 @@ root filesystem and remote access to the Dracut emergency shell mkdir -p %{buildroot}/usr/lib/dracut/modules.d cp -r 46sshd %{buildroot}/usr/lib/dracut/modules.d/ cp -r 99sshd-shadow-fixup %{buildroot}/usr/lib/dracut/modules.d/ +cp -r 99sshd-networkmanager %{buildroot}/usr/lib/dracut/modules.d/ %files %dir /usr/lib/dracut/modules.d/46sshd/ @@ -43,6 +59,9 @@ cp -r 99sshd-shadow-fixup %{buildroot}/usr/lib/dracut/modules.d/ %doc example/20-wired.network %doc example/90-networkd.conf +%files networkmanager +/usr/lib/dracut/modules.d/99sshd-networkmanager/module-setup.sh + %changelog * Sat May 27 2023 Georg Sauthoff - 0.6.5-1 - eliminate tmpfiles and fix Debian/Ubuntu support