Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically upgrade initoverlayfs on kernel upgrade #66

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ For illustration, consider a comparison of the sizes using dracut versus initove

**Using dracut + initoverlayfs**:
``` bash
# /usr/bin/initoverlayfs-install
# /usr/bin/initoverlayfs-install -f
# du -sh /boot/initramfs-6.5.5-300.fc39.x86_64.img
13M /boot/initramfs-6.5.5-300.fc39.x86_64.img
^^ <--- from 36M to 13M
Expand Down Expand Up @@ -129,7 +129,7 @@ dnf install -y epel-release
Once the deployment is completed, the next step is to execute the /usr/bin/initoverlayfs-install tool. This tool is responsible for generating both the initramfs and initoverlayfs images, along with the essential initoverlayfs.conf configuration.

``` bash
# /usr/bin/initoverlayfs-install
# /usr/bin/initoverlayfs-install -f
<SNIP>
initoverlayfs
kernel-modules
Expand Down
74 changes: 30 additions & 44 deletions bin/initoverlayfs-install
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,30 @@ exec_ext4() {
}

detect_initramfs() {
mkdir -p "${INITRAMFS_DUMP_DIR}"

echo "Extracting initrd into initoverlayfs..."

file_path="${INITRAMFS_DIR}/initramfs-$kver.img"
bin="$($SKIPCPIO_BIN "$file_path" | { read -r -N 6 bin && echo "$bin"; })"
case $bin in
$'\x1f\x8b'*)
CAT="zcat"
;;
BZh*)
CAT="bzcat"
;;
$'\x71\xc7'* | 070701)
CAT="cat"
;;
$'\x02\x21'*)
CAT="lz4 -d -c"
;;
$'\x89'LZO$'\0'*)
CAT="lzop -d -c"
;;
$'\x28\xB5\x2F\xFD'*)
CAT="zstd -d -c"
;;
*)
if echo "test" | xz | xzcat --single-stream > /dev/null 2>&1; then
CAT="xzcat --single-stream"
else
CAT="xzcat"
fi
;;
esac
mkdir -p "${INITRAMFS_DUMP_DIR}"

echo "Extracting initrd into initoverlayfs..."

file_path="${INITRAMFS_DIR}/initramfs-$kver.img"
skipcpio="/usr/lib/dracut/skipcpio"
if $skipcpio $file_path | gzip -t - >/dev/null 2>&1; then
CAT="zcat"
elif $skipcpio $file_path | zstd -q -c -t - >/dev/null 2>&1; then
CAT="zstd"
elif $skipcpio $file_path | xzcat -t - >/dev/null 2>&1; then
CAT="xzcat"
elif $skipcpio $file_path | lz4cat -t - >/dev/null 2>&1; then
CAT="lz4cat"
elif $skipcpio $file_path | bzip2 -t - >/dev/null 2>&1; then
CAT="bzcat"
elif $skipcpio $file_path | lzop -t - >/dev/null 2>&1; then
CAT="lzop"
else
CAT="cat"
fi

echo " - File path: ${file_path}"
echo " - Decompressor: $CAT"
echo " - File path: ${file_path}"
echo " - Decompressor: $CAT"
}

extract_initrd_into_initoverlayfs() {
Expand Down Expand Up @@ -127,18 +115,16 @@ extract_initrd_into_initoverlayfs() {

# main()

args="$*"
while [[ $# -gt 0 ]]; do
echo "$1"
case $1 in
--kver)
kver="$2"
shift 2
;;
-*)
echo "Unknown option $1"
exit 1
;;
*)
break;
shift 1
;;
esac
done
Expand All @@ -163,8 +149,8 @@ if ! [ -e "$INITOVERLAYFS_CONF" ] || ! grep -q '[^[:space:]]' "$INITOVERLAYFS_CO
printf "%s\n%s\n%s\n%s\n" \
"bootfs $boot_partition" \
"bootfstype ext4" \
"initoverlayfs_builder dracut -N -f -v -M --reproducible -o \"initoverlayfs fcoe\"" \
"initrd_builder dracut -N -f -v -M --reproducible -m \"kernel-modules udev-rules initoverlayfs systemd base\" -o \"bash systemd-initrd i18n kernel-modules-extra rootfs-block dracut-systemd usrmount fs-lib microcode_ctl-fw_dir_override shutdown nss-softokn\"" > $INITOVERLAYFS_CONF
"initoverlayfs_builder dracut -M -o \"initoverlayfs fcoe\"" \
"initrd_builder dracut -M -m \"kernel-modules udev-rules initoverlayfs systemd base\" -o \"bash systemd-initrd i18n kernel-modules-extra rootfs-block dracut-systemd usrmount fs-lib microcode_ctl-fw_dir_override shutdown nss-softokn\"" > $INITOVERLAYFS_CONF

erofs_compression_supported="true"
# shellcheck disable=SC2034
Expand All @@ -185,11 +171,11 @@ fi

erofs_compression=$(sed -ne "s/^erofs_compression\s//pg" "$INITOVERLAYFS_CONF")
initoverlayfs_builder=$(sed -ne "s/^initoverlayfs_builder\s//pg" "$INITOVERLAYFS_CONF")
/bin/bash -c "$initoverlayfs_builder --kver $kver"
/bin/bash -c "$initoverlayfs_builder $args"

detect_initramfs
extract_initrd_into_initoverlayfs

initrd_builder=$(sed -ne "s/^initrd_builder\s//pg" "$INITOVERLAYFS_CONF")
/bin/bash -c "$initrd_builder --kver $kver"
/bin/bash -c "$initrd_builder $args"

2 changes: 1 addition & 1 deletion build-scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

# Current version of initoverlayfs
VERSION=0.991
VERSION=0.992
# Specify if build is a official release or a snapshot build
IS_RELEASE=false
# Used for official releases. Increment if necessary
Expand Down
5 changes: 5 additions & 0 deletions initoverlayfs.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ install -D -m644 lib/systemd/system/pre-initoverlayfs-switch-root.service ${RPM_
%{_prefix}/lib/systemd/system/pre-initoverlayfs-switch-root.service

%changelog
* Mon Feb 12 2024 Eric Curtin <[email protected]> - 0.992-1
- Update to 0.992 release.
- Automatically rebuild kernel on upgrade (ecurtin)
- Build initrd in no-hostonly mode for generic initrd (ecurtin)

* Wed Jan 17 2024 Stephen Smoogen <[email protected]> - 0.991-1
- Update to 0.991 release.
- fork storage-init as a systemd unit (ecurtin)
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/boot-validation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [ -z "${RPM_EXIST}" ]; then
fi

echo -n "Install initoverlayfs"
/usr/bin/initoverlayfs-install
/usr/bin/initoverlayfs-install -f

exit_code="$?"

Expand Down
16 changes: 16 additions & 0 deletions lib/kernel/install.d/94-initoverlayfs.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/bash

COMMAND="$1"
KERNEL_VERSION="$2"

case "$COMMAND" in
add)
initoverlayfs-install -f --kver "$KERNEL_VERSION"
;;
remove)
rm -f /boot/initoverlayfs-$KERNEL_VERSION
;;
*)
exit 0
esac

Loading