Skip to content

Commit 4dd3627

Browse files
committed
test: initrd in /usr
Signed-off-by: Kai Lueke <[email protected]>
1 parent 31ba296 commit 4dd3627

File tree

5 files changed

+172
-1
lines changed

5 files changed

+172
-1
lines changed

dracut/03flatcar-network/parse-ip-for-networkd.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description=Write systemd-networkd units from cmdline
33
DefaultDependencies=false
44

5-
After=afterburn-network-kargs.service
5+
After=afterburn-network-kargs.service dracut-cmdline.service
66
PartOf=systemd-networkd.service
77
Before=systemd-networkd.service initrd-switch-root.target
88
# Switching the root filesystem terminates all running services with binaries from the initramfs, we need to finish before that happens

dracut/10diskless-generator/diskless-generator

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
33
# ex: ts=8 sw=4 sts=4 et filetype=sh
44

5+
# NOTE: The /usr.squashfs mounting for /sysusr is done in /minimal-init
6+
# but the /sysroot mounting is still done here as well as the rootfs RAM setup
7+
58
set -e
69

710
UNIT_DIR="${1:-/tmp}"

dracut/10usr-generator/usr-generator

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# by systemd-fstab-generator. This module is only needed for old
1111
# bootloaders that pass usr=.
1212

13+
# NOTE: Now done in /minimal-init but since the "mount.usr" generator also runs,
14+
# it seems ok to also keep the "usr" generator
1315
set -e
1416

1517
UNIT_DIR="${1:-/tmp}"

dracut/10verity-generator/verity-generator

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# This script generates a service that manages a dm-verity device for the chosen USR partition
66

7+
# NOTE: The verity setup is now done in /minimal-init and this logic should be inactive
8+
79
set -e
810

911
UNIT_DIR="${1:-/tmp}"

minimal-init

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/bin/sh
2+
set -eu
3+
busybox mount -n -t proc proc /proc
4+
busybox mount -n -t devtmpfs devtmpfs /dev
5+
busybox mount -n -t sysfs sysfs /sys
6+
busybox --install -s
7+
if [ ! -x "/dev/pts" ]; then mkdir /dev/pts; fi
8+
if [ ! -x "/dev/shm" ]; then mkdir /dev/shm; fi
9+
busybox mount -n -t devpts devpts /dev/pts -o gid=5,mode=620,ptmxmode=000
10+
11+
cmdline_arg() {
12+
local name="$1"
13+
local value="${2-}"
14+
for arg in $(cat /proc/cmdline); do
15+
if [[ "${arg%%=*}" == "${name}" ]]; then
16+
value="${arg#*=}"
17+
fi
18+
done
19+
echo "${value}"
20+
}
21+
22+
# Custom debug breakpoint
23+
if [ "$(cmdline_arg rd.earlyshell)" != "" ]; then
24+
busybox sh
25+
fi
26+
if [ "$(cmdline_arg rd.earlytrace)" != "" ]; then
27+
set -x
28+
fi
29+
30+
mdev -d
31+
mdev -s
32+
# Coldplugging but with using /sbin/modprobe (which is kmod) instead of busybox's modprobe
33+
# because busybox doesn't properly support the globs in modules.alias
34+
find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | xargs -0 /sbin/modprobe -abq || true
35+
# Required to access disks, but not autoloaded:
36+
modprobe sd_mod
37+
38+
if [ "$(cmdline_arg rd.earlyshell)" != "" ]; then
39+
busybox sh
40+
fi
41+
42+
find_usr() {
43+
local UEVENTLINE="$1"
44+
local DRIVE=
45+
local WAITINGMSG=
46+
while [ "${DRIVE}" = "" ]; do
47+
DRIVE="$({ grep -s -l -m 1 -r "${UEVENTLINE}" /sys/class/block/*/uevent || true; } | cut -d / -f 5)"
48+
if [ "${DRIVE}" = "" ] && [ "${WAITINGMSG}" = "" ]; then
49+
echo "Waiting for drive..." >&2
50+
WAITINGMSG=1
51+
fi
52+
done
53+
DRIVE="/dev/${DRIVE}"
54+
echo "${DRIVE}"
55+
}
56+
57+
# Ported code from the generators
58+
verityusr=$(cmdline_arg verity.usr)
59+
usrhash=$(cmdline_arg verity.usrhash)
60+
61+
case "${verityusr}" in
62+
LABEL=*)
63+
verityusr="LABEL=$(echo "$verityusr" | sed 's,/,\\x2f,g')"
64+
verityusr=$(find_usr "${verityusr}")
65+
;;
66+
UUID=*)
67+
verityusr="${verityusr#UUID=}"
68+
verityusr="UUID=$(echo "$verityusr" | tr "[:upper:]" "[:lower:]")"
69+
verityusr=$(find_usr "${verityusr}")
70+
;;
71+
PARTUUID=*)
72+
verityusr="${verityusr#PARTUUID=}"
73+
verityusr="PARTUUID=$(echo "$verityusr" | tr "[:upper:]" "[:lower:]")"
74+
verityusr=$(find_usr "${verityusr}")
75+
;;
76+
PARTLABEL=*)
77+
verityusr=$(find_usr "${verityusr}")
78+
;;
79+
esac
80+
81+
# Only proceed if the source is a path and we have sufficient parameters.
82+
if echo "${verityusr}" | grep -q "^/" && [ "${usrhash}" != "" ]; then
83+
# Hardcoded expected value from the image GPT layout
84+
veritysetup --panic-on-corruption --hash-offset=1065345024 open "${verityusr}" usr "${verityusr}" "${usrhash}"
85+
# If there's a hash mismatch during table initialization,
86+
# veritysetup reports it on stderr but still exits 0.
87+
# Manually check the target status and fail if invalid.
88+
status=$(dmsetup status usr | cut -d " " -f 4)
89+
if [ "${status}" != V ]; then
90+
echo "Verity setup failed" >&2
91+
exit 1
92+
fi
93+
fi
94+
95+
usr=$(cmdline_arg mount.usr $(cmdline_arg usr))
96+
usrfstype=$(cmdline_arg mount.usrfstype $(cmdline_arg usrfstype auto))
97+
usrflags=$(cmdline_arg mount.usrflags $(cmdline_arg usrflags ro))
98+
99+
case "${usr}" in
100+
LABEL=*)
101+
usr="LABEL=$(echo "$usr" | sed 's,/,\\x2f,g')"
102+
usr=$(find_usr "${usr}")
103+
;;
104+
UUID=*)
105+
usr="${usr#UUID=}"
106+
usr="UUID=$(echo "$usr" | tr "[:upper:]" "[:lower:]")"
107+
usr=$(find_usr "${usr}")
108+
;;
109+
PARTUUID=*)
110+
usr="${usr#PARTUUID=}"
111+
usr="PARTUUID=$(echo "$usr" | tr "[:upper:]" "[:lower:]")"
112+
usr=$(find_usr "${usr}")
113+
;;
114+
PARTLABEL=*)
115+
usr=$(find_usr "${usr}")
116+
;;
117+
esac
118+
119+
if [ "${usr}" = "" ] && [ -f /usr.squashfs ]; then
120+
usr=/usr.squashfs
121+
usrfstype=squashfs
122+
elif [ "${usrfstype}" = btrfs ] || [ "${usrfstype}" = auto ]; then
123+
if [ "$(echo ",${usrflags}," | grep -v -F ',ro,')" != "" ]; then
124+
true # Don't set "norecovery" when mounting rw
125+
else
126+
usrflags="${usrflags},rescue=nologreplay"
127+
fi
128+
fi
129+
# Only proceed if the source is a path.
130+
if echo "${usr}" | grep -v -q "^/"; then
131+
echo "No mountable /usr partition given (usr='${usr}')" >&2
132+
exit 1
133+
fi
134+
135+
echo "Mounting /usr from ${usr}"
136+
mount -t "${usrfstype}" -o "${usrflags}" "${usr}" /sysusr/usr
137+
138+
# Busybox doesn't load this for us
139+
modprobe loop
140+
losetup -r -f /sysusr/usr/lib/flatcar/bootengine.img
141+
mkdir /underlay /work
142+
mount -t tmpfs tmpfs /work
143+
mkdir /work/realinit /work/work
144+
mount -t squashfs /dev/loop0 /underlay
145+
mount -t overlay -o rw,lowerdir=/underlay,upperdir=/work/realinit,workdir=/work/work overlay /realinit
146+
mkdir -p /realinit/sysusr/usr
147+
mount -o move /sysusr/usr /realinit/sysusr/usr
148+
if [ "${usr}" = /usr.squashfs ]; then
149+
mkdir -p /oem
150+
mkdir -p /realinit/oem
151+
mount -o bind /oem /realinit/oem
152+
touch /realinit/usr.squashfs
153+
mount -o bind /usr.squashfs /realinit/usr.squashfs
154+
fi
155+
if [ "$(cmdline_arg rd.earlyshell)" != "" ]; then
156+
busybox sh
157+
fi
158+
killall mdev || true
159+
umount /proc
160+
umount /sys
161+
umount /dev/pts
162+
# Lazy unmount because /dev/console is held by the current process
163+
umount -l /dev
164+
exec switch_root /realinit /init

0 commit comments

Comments
 (0)