Skip to content

Commit 5894457

Browse files
authored
Enable Dracut's livenet rootfs handling when systemd-networkd is in use. (#10706)
1 parent a9360df commit 5894457

5 files changed

Lines changed: 127 additions & 5 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=LiveOS Artifacts Download Daemon
3+
After=network-online.target
4+
Wants=network-online.target
5+
6+
[Service]
7+
ExecStart=/sbin/azl-liveos-artifacts-download
8+
Type=oneshot
9+
10+
[Install]
11+
WantedBy=multi-user.target
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Dracut version 102 does not implement the code path that handles livenet
4+
# rootfs download (i.e. by calling /sbin/livenetroot) when systemd-networkd
5+
# is the underlying networking manager.
6+
#
7+
# This has been implemented in 103 (see https://github.com/dracut-ng/dracut-ng/pull/388)
8+
#
9+
# As a mitigation for 102, this script will be scheduled to be run after the
10+
# network stack is up and will basically call into the same livenet rootfs
11+
# handling code.
12+
13+
echo "executing azl-liveos-artifacts-download.sh" > /dev/kmsg
14+
15+
. /usr/lib/dracut-lib.sh
16+
. /lib/url-lib.sh
17+
18+
root=$(getarg root -d "")
19+
20+
# set dracut environment
21+
export fstype="auto"
22+
export DRACUT_SYSTEMD=1
23+
24+
# replace 'live:' with 'livetnet' so that livenetroot can detect it correctly.
25+
isoUrl="${root#live:}"
26+
netroot="livenet:"${isoUrl}
27+
28+
# Looking at livenetroot.sh, the first argument is unused in livenetroot.
29+
# So, we are just providing a placehold here to preserve the order.
30+
/sbin/livenetroot dummy $netroot
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From 5aa61cfd4aa5744171812c473ebd7b35e71c8c5a Mon Sep 17 00:00:00 2001
2+
From: George Mileka <gmileka@microsoft.com>
3+
Date: Fri, 30 Aug 2024 18:17:00 -0700
4+
Subject: [PATCH] Enable netroot for systemd-networkd - temporary fix till
5+
upgrading to 103+.
6+
7+
Dracut version 102 does not implement the code path that handles livenet
8+
rootfs download (i.e. by calling /sbin/livenetroot) when systemd-networkd
9+
is the underlying networking manager.
10+
11+
This has been implemented in 103 (see https://github.com/dracut-ng/dracut-ng/pull/388)
12+
13+
As a mitigation for 102, this patch allows Dracut's livenet module to schedule
14+
a daemon to run after the network stack is up and running. The daemon will
15+
then invoke the usual livenet rootfs handling code to download and pivot to
16+
the new rootfs.
17+
---
18+
modules.d/90livenet/module-setup.sh | 2 ++
19+
modules.d/90livenet/parse-livenet.sh | 8 ++++++++
20+
2 files changed, 10 insertions(+)
21+
22+
diff --git a/modules.d/90livenet/module-setup.sh b/modules.d/90livenet/module-setup.sh
23+
index db0def50..57fb384a 100755
24+
--- a/modules.d/90livenet/module-setup.sh
25+
+++ b/modules.d/90livenet/module-setup.sh
26+
@@ -17,6 +17,8 @@ install() {
27+
inst_hook cmdline 29 "$moddir/parse-livenet.sh"
28+
inst_hook initqueue/online 95 "$moddir/fetch-liveupdate.sh"
29+
inst_script "$moddir/livenetroot.sh" "/sbin/livenetroot"
30+
+ inst_simple "$moddir/azl-liveos-artifacts-download.service" "/etc/systemd/system/azl-liveos-artifacts-download.service"
31+
+ inst_script "$moddir/azl-liveos-artifacts-download.sh" "/sbin/azl-liveos-artifacts-download"
32+
if dracut_module_included "systemd-initrd"; then
33+
inst_script "$moddir/livenet-generator.sh" "$systemdutildir"/system-generators/dracut-livenet-generator
34+
fi
35+
diff --git a/modules.d/90livenet/parse-livenet.sh b/modules.d/90livenet/parse-livenet.sh
36+
index a1d14a8f..f8713eb5 100755
37+
--- a/modules.d/90livenet/parse-livenet.sh
38+
+++ b/modules.d/90livenet/parse-livenet.sh
39+
@@ -27,6 +27,14 @@ if get_url_handler "$liveurl" > /dev/null; then
40+
root="livenet" # quiet complaints from init
41+
# shellcheck disable=SC2034
42+
rootok=1
43+
+
44+
+ enableAzureLinuxDownloader=$(getarg rd.live.azldownloader=)
45+
+
46+
+ if [[ "$enableAzureLinuxDownloader" == "enable" ]]; then
47+
+ systemctl enable azl-liveos-artifacts-download
48+
+ systemctl start --no-block azl-liveos-artifacts-download
49+
+ fi
50+
+
51+
wait_for_dev -n /dev/root
52+
else
53+
info "livenet: no url handler for $liveurl"
54+
--
55+
2.34.1
56+

SPECS/dracut/dracut.signatures.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"00-vrf.conf": "e2885a4b090d8ca3771e60ce6dcd8b849e28ce5002a5c7b71ff796a92deb2810",
77
"00-xen.conf": "8b7a89b7716cb40a9c0d681caed6994d81ff4dfad4fe50cea15cd47b885dc5a6",
88
"50-noxattr.conf": "61d95f05890ac6ee3355d0a386dd5645d82b7a4202d90305d997fd18c6d139dd",
9+
"azl-liveos-artifacts-download.service": "888be8c82297cccd510d7f963611c2360ae67559826b2b474da6d9935237de64",
10+
"azl-liveos-artifacts-download.sh": "f21dc68de8c81d8a8128e7a9d7be45d25978f0b5e47a4cf1a2d97b1e171ec045",
911
"dracut-102.tar.gz": "601b175cbf4d2ee902bb7bda3af8826ae2ca060c1af880f6da5a833413f4ec70",
1012
"lgpl-2.1.txt": "dc626520dcd53a22f727af3ee42c770e56c97a64fe3adb063799d8ab032fe551",
1113
"megaraid.conf": "914824cdbe0c525b71efa05a75e453335b0068beb8bc28bef2a5866d74bf7dd4",
1214
"module-setup.sh": "8f5a0d3cc393d78bcb523b0d53c578d2767d688f00e84b525355bbb31d753da4",
1315
"overlayfs-mount.sh": "28f47c107a4435c5153bdb5b2f92f20b7a75bf3932216635ee810875c27dd55b"
1416
}
15-
}
17+
}

SPECS/dracut/dracut.spec

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Summary: dracut to create initramfs
55
Name: dracut
66
Version: 102
7-
Release: 6%{?dist}
7+
Release: 7%{?dist}
88
# The entire source code is GPLv2+
99
# except install/* which is LGPLv2+
1010
License: GPLv2+ AND LGPLv2+
@@ -24,12 +24,29 @@ Source8: 00-virtio.conf
2424
Source9: 00-vrf.conf
2525
Source10: 00-xen.conf
2626
Source11: 50-noxattr.conf
27+
# The 90livenet/azl-liveos-artifacts-download.service and
28+
# 90livenet/azl-liveos-artifacts-download.sh are part of the
29+
# add-livenet-download-service.patch. They are kept separate for easier
30+
# code reviews given that they are new to Dracut.
31+
Source12: 90livenet/azl-liveos-artifacts-download.service
32+
Source13: 90livenet/azl-liveos-artifacts-download.sh
2733

2834
# allow-liveos-overlay-no-user-confirmation-prompt.patch has been introduced by
29-
# the Mariner team to allow skipping the user confirmation prompt during boot
30-
# when the overlay of the liveos is backed by ram. This allows the machine to
31-
# boot without being blocked on user input in such a scenario.
35+
# the Azure Linux team to allow skipping the user confirmation prompt during
36+
# boot when the overlay of the liveos is backed by ram. This allows the machine
37+
# to boot without being blocked on user input in such a scenario.
3238
Patch: allow-liveos-overlay-no-user-confirmation-prompt.patch
39+
# add-livenet-download-service.patch has been introduced by the Azure Linux
40+
# team to enable Dracut's livenet module to download and ISO image and proceed
41+
# with a rootfs overlay mouting/pivoting (using Dracut's existing dmsquash-live
42+
# module). This enables PXE booting using an ISO image with an embededed rootfs
43+
# image.
44+
# This is a temporary fix until Dracut is upgraded to 103.
45+
# - For reference, see https://github.com/dracut-ng/dracut-ng/issues/719.
46+
# This patch relies on two new files (azl-liveos-artifacts-download.service and
47+
# azl-liveos-artifacts-download.sh) - which are included as separate sources in
48+
# this package.
49+
Patch: add-livenet-download-service.patch
3350
Patch: 0006-dracut.sh-validate-instmods-calls.patch
3451
Patch: 0011-Remove-reference-to-kernel-module-zlib-in-fips-module.patch
3552
Patch: 0012-fix-dracut-functions-avoid-awk-in-get_maj_min.patch
@@ -185,6 +202,9 @@ install -m 0644 %{SOURCE9} %{buildroot}%{_sysconfdir}/dracut.conf.d/00-vrf.conf
185202
install -m 0644 %{SOURCE10} %{buildroot}%{_sysconfdir}/dracut.conf.d/00-xen.conf
186203
install -m 0644 %{SOURCE11} %{buildroot}%{_sysconfdir}/dracut.conf.d/50-noxattr.conf
187204

205+
install -m 0644 %{SOURCE12} %{buildroot}%{dracutlibdir}/modules.d/90livenet/azl-liveos-artifacts-download.service
206+
install -m 0755 %{SOURCE13} %{buildroot}%{dracutlibdir}/modules.d/90livenet/azl-liveos-artifacts-download.sh
207+
188208
mkdir -p %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
189209
install -p -m 0755 %{SOURCE4} %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
190210
install -p -m 0755 %{SOURCE5} %{buildroot}%{dracutlibdir}/modules.d/20overlayfs/
@@ -290,6 +310,9 @@ ln -srv %{buildroot}%{_bindir}/%{name} %{buildroot}%{_sbindir}/%{name}
290310
%dir %{_sharedstatedir}/%{name}/overlay
291311

292312
%changelog
313+
* Thu Oct 31 2024 George Mileka <gmileka@microsoft.com> - 102-7
314+
- Augment livenet module with a download daemon.
315+
293316
* Thu Oct 10 2024 Thien Trung Vuong <tvuong@microsoft.com> - 102-6
294317
- Add patch to make tpm2-tss an optional dependency for systemd-pcrphase
295318

0 commit comments

Comments
 (0)