Skip to content

Commit c17c5b7

Browse files
lnykrynharaldh
authored andcommitted
fix(network-manager): run as a service if systemd module is present
In the current state, services that depend on network need to use dracut hooks, since nothing with pull in the network targets into the transaction. In the future, it would be nice to provide developers on systemd-only systems the possibility to not use dracut hooks at all, but simply put normal systemd services into the initrd. Also, some modules even right now depend on systemd ordering, like cryptsetup, so let's make sure, that the ordering inside systemd work properly as well.
1 parent 34c73b3 commit c17c5b7

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

modules.d/35network-manager/module-setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ install() {
3434
inst /usr/libexec/nm-initrd-generator
3535
inst_multiple -o teamd dhclient
3636
inst_hook cmdline 99 "$moddir/nm-config.sh"
37+
if dracut_module_included "systemd"; then
38+
inst_simple "${moddir}/nm-run.service" "${systemdsystemunitdir}/nm-run.service"
39+
$SYSTEMCTL -q --root "$initdir" enable nm-run.service
40+
fi
41+
3742
inst_hook initqueue/settled 99 "$moddir/nm-run.sh"
43+
3844
inst_rules 85-nm-unmanaged.rules
3945
inst_libdir_file "NetworkManager/$_nm_version/libnm-device-plugin-team.so"
4046
inst_simple "$moddir/nm-lib.sh" "/lib/nm-lib.sh"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is part of dracut.
2+
# SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
[Unit]
5+
#make sure all devices showed up
6+
Wants=systemd-udev-settle.service
7+
After=systemd-udev-settle.service
8+
9+
#pull the network targets into transaction
10+
Wants=network.target network-online.target
11+
Before=network.target network-online.target
12+
13+
#run before we try to mount anything from the dracut hooks
14+
Before=dracut-initqueue.service
15+
16+
#do not run, if there is no configuration
17+
ConditionPathExistsGlob=|/usr/lib/NetworkManager/system-connections/*
18+
ConditionPathExistsGlob=|/run/NetworkManager/system-connections/*
19+
ConditionPathExistsGlob=|/etc/NetworkManager/system-connections/*
20+
ConditionPathExistsGlob=|/etc/sysconfig/network-scripts/ifcfg-*
21+
22+
[Service]
23+
#run the script and wait before it finishes
24+
Type=oneshot
25+
ExecStart=/usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
26+
27+
[Install]
28+
WantedBy=initrd.target

modules.d/35network-manager/nm-run.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#!/bin/sh
22

3+
type source_hook >/dev/null 2>&1 || . /lib/dracut-lib.sh
4+
35
if [ -e /tmp/nm.done ]; then
46
return
57
fi
68

9+
[ -z "$DRACUT_SYSTEMD" ] && \
710
for i in /usr/lib/NetworkManager/system-connections/* \
811
/run/NetworkManager/system-connections/* \
912
/etc/NetworkManager/system-connections/* \
1013
/etc/sysconfig/network-scripts/ifcfg-*; do
1114
[ -f "$i" ] || continue
1215
/usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
13-
14-
if [ -s /run/NetworkManager/initrd/hostname ]; then
15-
cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname
16-
fi
1716
break
1817
done
1918

19+
if [ -s /run/NetworkManager/initrd/hostname ]; then
20+
cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname
21+
fi
22+
2023
for _i in /sys/class/net/*
2124
do
2225
state=/run/NetworkManager/devices/$(cat $_i/ifindex)

modules.d/40network/netroot.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ if [ -z "$2" ]; then
6565
fi
6666

6767
# Check: do we really know how to handle (net)root?
68+
if [ -z "$root" ]; then
69+
root=$(getarg root=)
70+
fi
6871
[ -z "$root" ] && die "No or empty root= argument"
6972
[ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"
7073

0 commit comments

Comments
 (0)