Skip to content

Commit 6794e4b

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

File tree

5 files changed

+149
-1
lines changed

5 files changed

+149
-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: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
usr=$(cmdline_arg mount.usr $(cmdline_arg usr))
59+
usrfstype=$(cmdline_arg mount.usrfstype $(cmdline_arg usrfstype auto))
60+
usrflags=$(cmdline_arg mount.usrflags $(cmdline_arg usrflags ro))
61+
62+
case "${usr}" in
63+
LABEL=*)
64+
usr="LABEL=$(echo "$usr" | sed 's,/,\\x2f,g')"
65+
usr=$(find_usr "${usr}")
66+
;;
67+
UUID=*)
68+
usr="${usr#UUID=}"
69+
usr="UUID=$(echo "$usr" | tr "[:upper:]" "[:lower:]")"
70+
usr=$(find_usr "${usr}")
71+
;;
72+
PARTUUID=*)
73+
usr="${usr#PARTUUID=}"
74+
usr="PARTUUID=$(echo "$usr" | tr "[:upper:]" "[:lower:]")"
75+
usr=$(find_usr "${usr}")
76+
;;
77+
PARTLABEL=*)
78+
usr=$(find_usr "${usr}")
79+
;;
80+
esac
81+
82+
if [ "${usr}" = "" ] && [ -f /usr.squashfs ]; then
83+
usr=/usr.squashfs
84+
usrfstype=squashfs
85+
elif [ "${usrfstype}" = btrfs ] || [ "${usrfstype}" = auto ]; then
86+
if [ "$(echo ",${usrflags}," | grep -v -F ',ro,')" != "" ]; then
87+
true # Don't set "norecovery" when mounting rw
88+
else
89+
usrflags="${usrflags},rescue=nologreplay"
90+
fi
91+
fi
92+
# Only proceed if the source is a path.
93+
if echo "${usr}" | grep -q "^/"; then
94+
echo "No mountable /usr partition given (usr='${usr}')" >&2
95+
exit 1
96+
fi
97+
98+
usrhash=$(cmdline_arg verity.usrhash)
99+
if [ "${usrhash}" != "" ]; then
100+
# Hardcoded expected value from the image GPT layout
101+
veritysetup --panic-on-corruption --hash-offset=1065345024 open "${usr}" usr "${usr}" "${usrhash}"
102+
# If there's a hash mismatch during table initialization,
103+
# veritysetup reports it on stderr but still exits 0.
104+
# Manually check the target status and fail if invalid.
105+
read off len tgt status addl <<<$(dmsetup status usr)
106+
if [ "${status}" != V ]; then
107+
echo "Verity setup failed" >&2
108+
exit 1
109+
fi
110+
fi
111+
112+
echo "Mounting /usr from ${usr}"
113+
mount -t "${usrfstype}" -o "${usrflags}" "${usr}" /sysusr/usr
114+
115+
# Busybox doesn't load this for us
116+
modprobe loop
117+
losetup -r -f /sysusr/usr/lib/flatcar/bootengine.img
118+
mkdir /underlay /work
119+
mount -t tmpfs tmpfs /work
120+
mkdir /work/realinit /work/work
121+
mount -t squashfs /dev/loop0 /underlay
122+
mount -t overlay -o rw,lowerdir=/underlay,upperdir=/work/realinit,workdir=/work/work overlay /realinit
123+
mkdir -p /realinit/sysusr/usr
124+
mount -o move /sysusr/usr /realinit/sysusr/usr
125+
if [ "${usr}" = /usr.squashfs ]; then
126+
mkdir -p /oem
127+
mkdir -p /realinit/oem
128+
mount -o bind /oem /realinit/oem
129+
touch /realinit/usr.squashfs
130+
mount -o bind /usr.squashfs /realinit/usr.squashfs
131+
fi
132+
if [ "$(cmdline_arg rd.earlyshell)" != "" ]; then
133+
busybox sh
134+
fi
135+
killall mdev || true
136+
umount /proc
137+
umount /sys
138+
umount /dev/pts
139+
# Lazy unmount because /dev/console is held by the current process
140+
umount -l /dev
141+
exec switch_root /realinit /init

0 commit comments

Comments
 (0)