Skip to content

Commit 8fae246

Browse files
authored
Merge pull request #2835 from flatcar/chewi/pre-dracut
Various changes in preparation for upgrading Dracut
2 parents 47e6095 + 1439806 commit 8fae246

18 files changed

+1067
-167
lines changed

build_dev_binpkgs

+29-30
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ skip_packages_default="dev-lang/rust,dev-lang/rust-bin,dev-lang/go,dev-lang/go-b
1919
# Developer-visible flags.
2020
DEFINE_string board "${DEFAULT_BOARD}" \
2121
"The board to build packages for."
22-
DEFINE_string skip_packages "${skip_packages_default[@]}" \
22+
DEFINE_string skip_packages "${skip_packages_default}" \
2323
"Comma-separated list of packages in the dependency tree to skip."
2424
DEFINE_boolean pretend "${FLAGS_FALSE}" \
25-
"List packages that would be built but do not actually build."
25+
"List packages that would be built but do not actually build."
2626

27-
FLAGS_HELP="usage: $(basename $0) [flags] [packages]
27+
FLAGS_HELP="usage: $(basename "$0") [flags] [packages]
2828
2929
build_dev_binpkgs builds binary packages for all dependencies of [packages]
3030
that are not present in '/build/<board>/var/lib/portage/pkgs/'.
3131
Useful for publishing a complete set of packages to a binhost.
3232
33-
[packages] defaults to '${packages_default}' if not specified.
33+
[packages] defaults to '${packages_default[*]}' if not specified.
3434
"
3535

3636
# Parse command line
@@ -46,43 +46,42 @@ fi
4646
# --
4747

4848
function my_board_emerge() {
49-
PORTAGE_CONFIGROOT="/build/${FLAGS_board}" SYSROOT="${SYSROOT:-/build/${FLAGS_board}}" ROOT="/build/${FLAGS_board}" sudo -E emerge "${@}"
49+
PORTAGE_CONFIGROOT="/build/${FLAGS_board}" SYSROOT="${SYSROOT:-/build/${FLAGS_board}}" ROOT="/build/${FLAGS_board}" sudo -E emerge "${@}"
5050
}
5151
# --
5252

53-
pkg_build_list="$(mktemp)"
54-
pkg_skipped_list="${pkg_build_list}-skip"
55-
trap 'rm -f "${pkg_build_list}" "${pkg_skipped_list}"' EXIT
53+
pkg_build_list=()
54+
pkg_skipped_list=()
5655

5756
info "Collecting list of binpkgs to build"
5857

59-
my_board_emerge --pretend --emptytree ${@} \
60-
| grep '\[ebuild' \
61-
| sed 's/^\[[^]]\+\] \([^ :]\+\)*:.*/\1/' \
62-
| while read pkg; do
63-
if [ -f "/build/${FLAGS_board}/var/lib/portage/pkgs/${pkg}.tbz2" ] ; then
64-
continue
65-
fi
66-
skip=""
67-
for s in ${FLAGS_skip_packages//,/ }; do
68-
if [[ ${pkg} = ${s}-* ]] ; then
69-
echo -n "${pkg} " >> "${pkg_skipped_list}"
70-
skip="true"
71-
break
58+
# Normally, BDEPENDs are only installed to the SDK, but the point of this script
59+
# is to install them to the board root because the dev container uses a board
60+
# profile. This is easily achieved using --root-deps. Since it is still the SDK
61+
# doing the building, which might have different package versions available to
62+
# the board profile, we have to be careful not to include SDK BDEPENDs in the
63+
# list of binary packages to publish, hence the sed call.
64+
while read -r pkg; do
65+
[[ -f /build/${FLAGS_board}/var/lib/portage/pkgs/${pkg}.tbz2 ]] && continue
66+
IFS=,
67+
for s in ${FLAGS_skip_packages}; do
68+
if [[ ${pkg} == ${s}-* ]] ; then
69+
pkg_skipped_list+=("${pkg}")
70+
continue 2
7271
fi
7372
done
74-
[[ -z ${skip} ]] || continue
75-
echo "=${pkg}" | tee -a "${pkg_build_list}" | sed 's/^/ /'
76-
done
73+
unset IFS
74+
pkg_build_list+=("=${pkg}")
75+
echo " =${pkg}"
76+
done < <(my_board_emerge --pretend --emptytree --root-deps "${@}" |
77+
sed -n "/\[ebuild .* to \/build\/${FLAGS_board}\/ /s/^\[[^]]\+\] \([^ :]\+\)*:.*/\1/p")
7778
# --
7879

79-
if [ -f "${pkg_skipped_list}" ] ; then
80-
info "Skipping binpkgs '$(cat "${pkg_skipped_list}")' because these are in the skip list."
80+
if [[ ${#pkg_skipped_list[@]} -gt 0 ]]; then
81+
info "Skipping binpkgs '${pkg_skipped_list[*]}' because these are in the skip list."
8182
fi
8283

8384
pretend=""
84-
if [[ "${FLAGS_pretend}" -eq "${FLAGS_TRUE}" ]]; then
85-
pretend="--pretend"
86-
fi
85+
[[ ${FLAGS_pretend} -eq ${FLAGS_TRUE} ]] && pretend="--pretend"
8786

88-
my_board_emerge --buildpkg ${pretend} $(cat "${pkg_build_list}")
87+
my_board_emerge --buildpkg ${pretend} "${pkg_build_list[@]}"

build_library/extract-initramfs-from-vmlinuz.sh

+34-65
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,35 @@
77
# This will create one or more out-dir/rootfs-N directories that contain the contents of the initramfs.
88

99
set -euo pipefail
10-
# check for unzstd. Will abort the script with an error message if the tool is not present.
11-
unzstd -V >/dev/null
10+
11+
# check for xzcat. Will abort the script with an error message if the tool is not present.
12+
xzcat -V >/dev/null
13+
1214
fail() {
1315
echo "${*}" >&2
1416
exit 1
1517
}
1618

17-
# Stolen from extract-vmlinux and modified.
18-
try_decompress() {
19-
local header="${1}"
20-
local no_idea="${2}"
21-
local tool="${3}"
22-
local image="${4}"
23-
local tmp="${5}"
24-
local output_basename="${6}"
25-
26-
local pos
27-
local tool_filename=$(echo "${tool}" | cut -f1 -d' ')
28-
# The obscure use of the "tr" filter is to work around older versions of
29-
# "grep" that report the byte offset of the line instead of the pattern.
19+
find_xz_headers() {
20+
grep --fixed-strings --text --byte-offset --only-matching $'\xFD\x37\x7A\x58\x5A\x00' "$1" | cut -d: -f1
21+
}
3022

31-
# Try to find the header and decompress from here.
32-
for pos in $(tr "${header}\n${no_idea}" "\n${no_idea}=" < "${image}" |
33-
grep --text --byte-offset --only-matching "^${no_idea}")
34-
do
35-
pos=${pos%%:*}
36-
# Disable error handling, because we will be potentially
37-
# giving the tool garbage or a valid archive with some garbage
38-
# appended to it. So let the tool extract the valid archive
39-
# and then complain about the garbage at the end, but don't
40-
# fail the script because of it.
41-
set +e; tail "-c+${pos}" "${image}" | "${tool}" >"${tmp}/out" 2>/dev/null; set -e;
42-
if [ -s "${tmp}/out" ]; then
43-
mv "${tmp}/out" "${output_basename}-${tool_filename}-at-${pos}"
44-
else
45-
rm -f "${tmp}/out"
46-
fi
47-
done
23+
decompress_at() {
24+
# Data may not really be a valid xz, so allow for errors.
25+
tail "-c+$((${2%:*} + 1))" "$1" | xzcat 2>/dev/null || true
4826
}
4927

50-
try_unzstd_decompress() {
51-
local image="${1}"
52-
local tmp="${2}"
53-
local output_basename="${3}"
54-
try_decompress '(\265/\375' xxx unzstd "${image}" "${tmp}" "${output_basename}"
28+
try_extract() {
29+
# cpio can do strange things when given garbage, so do a basic check.
30+
[[ $(head -c6 "$1") == 070701 ]] || return 0
31+
32+
# There may be multiple concatenated archives so try cpio till it fails.
33+
while cpio --quiet --extract --make-directories --directory="${out}/rootfs-${ROOTFS_IDX}" --nonmatching 'dev/*' 2>/dev/null; do
34+
ROOTFS_IDX=$(( ROOTFS_IDX + 1 ))
35+
done < "$1"
36+
37+
# Last cpio attempt may or may not leave an empty directory.
38+
rmdir "${out}/rootfs-${ROOTFS_IDX}" 2>/dev/null || ROOTFS_IDX=$(( ROOTFS_IDX + 1 ))
5539
}
5640

5741
me="${0##*/}"
@@ -65,37 +49,22 @@ if [[ ! -s "${image}" ]]; then
6549
fi
6650
mkdir -p "${out}"
6751

68-
tmp=$(mktemp --directory /tmp/eifv-XXXXXX)
69-
trap "rm -rf ${tmp}" EXIT
52+
tmp=$(mktemp --directory eifv-XXXXXX)
53+
trap 'rm -rf -- "${tmp}"' EXIT
54+
ROOTFS_IDX=0
7055

71-
tmp_dec="${tmp}/decompress"
72-
mkdir "${tmp_dec}"
73-
fr_prefix="${tmp}/first-round"
56+
# arm64 kernels are not compressed, so try decompressing once.
57+
# Other kernels are compressed, so also try decompressing twice.
58+
for OFF1 in $(find_xz_headers "${image}")
59+
do
60+
decompress_at "${image}" "${OFF1}" > "${tmp}/initrd.maybe_cpio_or_elf"
61+
try_extract "${tmp}/initrd.maybe_cpio_or_elf"
7462

75-
ROOTFS_IDX=0
76-
perform_round() {
77-
local image="${1}"
78-
local tmp_dec="${2}"
79-
local round_prefix="${3}"
80-
try_unzstd_decompress "${image}" "${tmp_dec}" "${round_prefix}"
81-
for rnd in "${round_prefix}"*; do
82-
if [[ $(file --brief "${rnd}") =~ 'cpio archive' ]]; then
83-
mkdir -p "${out}/rootfs-${ROOTFS_IDX}"
84-
# On Linux 6.10, the first rootfs is an extra ghost rootfs of 336K, that has a corrupted CPIO
85-
cpio --quiet --extract --make-directories --directory="${out}/rootfs-${ROOTFS_IDX}" --nonmatching 'dev/*' < $rnd || true
86-
ROOTFS_IDX=$(( ROOTFS_IDX + 1 ))
87-
fi
63+
for OFF2 in $(find_xz_headers "${tmp}/initrd.maybe_cpio_or_elf")
64+
do
65+
decompress_at "${tmp}/initrd.maybe_cpio_or_elf" "${OFF2}" > "${tmp}/initrd.maybe_cpio"
66+
try_extract "${tmp}/initrd.maybe_cpio"
8867
done
89-
}
90-
91-
shopt -s nullglob
92-
perform_round "${image}" "${tmp_dec}" "${fr_prefix}"
93-
for fr in "${fr_prefix}"*; do
94-
fr_files="${fr}-files"
95-
fr_dec="${fr_files}/decompress"
96-
mkdir -p "${fr_dec}"
97-
sr_prefix="${fr_files}/second-round"
98-
perform_round "${fr}" "${fr_dec}" "${sr_prefix}"
9968
done
10069

10170
if [[ ${ROOTFS_IDX} -eq 0 ]]; then
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- The kernel image and its embedded initrd are now compressed with xz rather than zstd. This gives greater compression at the cost of decompression performance. Systems may therefore now be ever so slightly slower to boot, but this was necessary to avoid running out of space in the /boot partition. Further measures to address the space issue are planned, and perhaps we can switch back to zstd in a later release.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Temporarily put the SDK version ahead for sd-json support in Dracut.
2+
=sys-apps/systemd-257.5 ~amd64 ~arm64
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
DIST systemd-256.9.tar.gz 15774953 BLAKE2B caeff33d0906583094a44ab89fe9a9c1832a665f8cc768f86c55c5100bdd5c2b1500b2cd65e9519ef21d79bff92d1da3e84240793099a0e0c508afba3669c46e SHA512 aba7a0f7149fe3d28d9f930f244d5b997c28721e93e6f0768b0f0f1c918c87a0e8b7b347cffb2faa4740ca3ee3b04984454e85757365090a2cf32aba09f70681
2+
DIST systemd-257.5.tar.gz 16232112 BLAKE2B 142baef9b09217ea117ac09923604f7520a36d4c63cf04a78d1c4fbf7b057b977f5c77418168c0308a8dc6b48ccc6324438f30c87de8642e8e9cf12b47f90475 SHA512 9e5352c20c9edac53f302a534532035185139998628ed0a85411f440df47f1dd7cce6651aec787484809bb1aa2825008d062714c37936cbfd08451fbe29a998f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
From bffb2a48796a2736d7fb7328d2a88b1cbb812b12 Mon Sep 17 00:00:00 2001
2+
From: Sayan Chowdhury <[email protected]>
3+
Date: Fri, 16 Dec 2022 16:28:26 +0530
4+
Subject: [PATCH 6/8] Revert "getty: Pass tty to use by agetty via stdin"
5+
6+
This reverts commit b4bf9007cbee7dc0b1356897344ae2a7890df84c.
7+
8+
This is to work around a SELinux denial that happens when setting up standard
9+
input for serial consoles (which is used for SSH connections).
10+
11+
Signed-off-by: Sayan Chowdhury <[email protected]>
12+
---
13+
units/console-getty.service.in | 4 +---
14+
units/[email protected] | 4 +---
15+
units/[email protected] | 4 +---
16+
units/[email protected] | 4 +---
17+
4 files changed, 4 insertions(+), 12 deletions(-)
18+
19+
diff --git a/units/console-getty.service.in b/units/console-getty.service.in
20+
index 33e6368db1..1f2d8b910f 100644
21+
--- a/units/console-getty.service.in
22+
+++ b/units/console-getty.service.in
23+
@@ -22,12 +22,10 @@ ConditionPathExists=/dev/console
24+
[Service]
25+
# The '-o' option value tells agetty to replace 'login' arguments with '--' for
26+
# safety, and then the entered username.
27+
-ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear --keep-baud 115200,57600,38400,9600 - ${TERM}
28+
+ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear --keep-baud 115200,57600,38400,9600 console ${TERM}
29+
Type=idle
30+
Restart=always
31+
UtmpIdentifier=cons
32+
-StandardInput=tty
33+
-StandardOutput=tty
34+
TTYPath=/dev/console
35+
TTYReset=yes
36+
TTYVHangup=yes
37+
diff --git a/units/[email protected] b/units/[email protected]
38+
index 7573532d6d..5f27653d1f 100644
39+
--- a/units/[email protected]
40+
+++ b/units/[email protected]
41+
@@ -27,13 +27,11 @@ Before=rescue.service
42+
[Service]
43+
# The '-o' option value tells agetty to replace 'login' arguments with '--' for
44+
# safety, and then the entered username.
45+
-ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear - ${TERM}
46+
+ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear pts/%I ${TERM}
47+
Type=idle
48+
Restart=always
49+
RestartSec=0
50+
UtmpIdentifier=pts/%I
51+
-StandardInput=tty
52+
-StandardOutput=tty
53+
TTYPath=/dev/pts/%I
54+
TTYReset=yes
55+
TTYVHangup=yes
56+
diff --git a/units/[email protected] b/units/[email protected]
57+
index f30bba406d..1819627d1c 100644
58+
--- a/units/[email protected]
59+
+++ b/units/[email protected]
60+
@@ -36,13 +36,11 @@ ConditionPathExists=/dev/tty0
61+
[Service]
62+
# The '-o' option value tells agetty to replace 'login' arguments with '--' for
63+
# safety, and then the entered username.
64+
-ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear - ${TERM}
65+
+ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear %I ${TERM}
66+
Type=idle
67+
Restart=always
68+
RestartSec=0
69+
UtmpIdentifier=%I
70+
-StandardInput=tty
71+
-StandardOutput=tty
72+
TTYPath=/dev/%I
73+
TTYReset=yes
74+
TTYVHangup=yes
75+
diff --git a/units/[email protected] b/units/[email protected]
76+
index 20a5eb2754..ba4cbc0edb 100644
77+
--- a/units/[email protected]
78+
+++ b/units/[email protected]
79+
@@ -32,12 +32,10 @@ Before=rescue.service
80+
[Service]
81+
# The '-o' option value tells agetty to replace 'login' arguments with '--' for
82+
# safety, and then the entered username.
83+
-ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear --keep-baud 115200,57600,38400,9600 - ${TERM}
84+
+ExecStart=-/sbin/agetty -o '-- \\u' --noreset --noclear --keep-baud 115200,57600,38400,9600 %I ${TERM}
85+
Type=idle
86+
Restart=always
87+
UtmpIdentifier=%I
88+
-StandardInput=tty
89+
-StandardOutput=tty
90+
TTYPath=/dev/%I
91+
TTYReset=yes
92+
TTYVHangup=yes

0 commit comments

Comments
 (0)