From dd3daa0560e4e4f809b42a901cd79076d3577f96 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Tue, 23 Jul 2024 16:39:13 +0200 Subject: [PATCH 15/32] feat(squash): split 95squash-squashfs from 99squash 99squash only allows squashing the files using squashfs. In order to make the implementation for different filesystems easier split out the squashfs specific parts into 95squash-squashfs. While at it rename the root image contained in the initrd to squashfs-root.img. This allows tools like lsinitrd to detect the filesystem used later on. Signed-off-by: Philipp Rudo (cherry picked from commit f281606f110be1549cd6b1cd34828653879a5f50) Related: RHEL-43460 --- modules.d/95squash-squashfs/module-setup.sh | 48 ++++++++++++++++++ modules.d/99squash/init-squash.sh | 2 +- modules.d/99squash/module-setup.sh | 54 ++++++++++++--------- 3 files changed, 80 insertions(+), 24 deletions(-) create mode 100755 modules.d/95squash-squashfs/module-setup.sh diff --git a/modules.d/95squash-squashfs/module-setup.sh b/modules.d/95squash-squashfs/module-setup.sh new file mode 100755 index 00000000..83973700 --- /dev/null +++ b/modules.d/95squash-squashfs/module-setup.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +check() { + require_binaries mksquashfs unsquashfs || return 1 + require_kernel_modules squashfs || return 1 + + return 255 +} + +depends() { + echo "squash" + return 0 +} + +squashfs_install() { + hostonly="" instmods "squashfs" +} + +squashfs_installpost() { + local _img="$squashdir/squashfs-root.img" + local _comp + + # shellcheck disable=SC2086 + if [[ $squash_compress ]]; then + if ! mksquashfs /dev/null "$DRACUT_TMPDIR"/.squash-test.img -no-progress -comp $squash_compress &> /dev/null; then + dwarn "mksquashfs doesn't support compressor '$squash_compress', failing back to default compressor." + else + _comp="$squash_compress" + fi + fi + + # shellcheck disable=SC2086 + if ! mksquashfs "$initdir" "$_img" \ + -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \ + -no-progress ${_comp:+-comp $_comp} \ + -e "$squashdir" 1> /dev/null; then + dfatal "Failed making squash image" + exit 1 + fi +} + +install() { + if [[ $DRACUT_SQUASH_POST_INST ]]; then + squashfs_installpost + else + dstdir="$squashdir" squashfs_install + fi +} diff --git a/modules.d/99squash/init-squash.sh b/modules.d/99squash/init-squash.sh index 59769f62..42a9a86f 100755 --- a/modules.d/99squash/init-squash.sh +++ b/modules.d/99squash/init-squash.sh @@ -21,7 +21,7 @@ modprobe overlay # Mount the squash image mount -t ramfs ramfs /squash mkdir -p /squash/root /squash/overlay/upper /squash/overlay/work -mount -t squashfs -o ro,loop /squash-root.img /squash/root +mount -t squashfs -o ro,loop /squashfs-root.img /squash/root # Setup new root overlay mkdir /newroot diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh index 96d097af..015944c2 100755 --- a/modules.d/99squash/module-setup.sh +++ b/modules.d/99squash/module-setup.sh @@ -1,17 +1,42 @@ #!/bin/bash check() { - require_binaries mksquashfs unsquashfs || return 1 - require_kernel_modules squashfs loop overlay || return 1 + require_kernel_modules loop overlay || return 1 return 255 } depends() { - echo "systemd-initrd" + local _handler + + _handler=$(squash_get_handler) || return 1 + + echo "systemd-initrd $_handler" return 0 } +squash_get_handler() { + local _module _handler + + for _module in squash-squashfs; do + if dracut_module_included "$_module"; then + _handler="$_module" + break + fi + done + + if [ -z "$_handler" ]; then + if check_module "squash-squashfs"; then + _handler="squash-squashfs" + else + dfatal "No valid handler for found" + return 1 + fi + fi + + echo "$_handler" +} + squash_install() { local _busybox _busybox=$(find_binary busybox) @@ -36,7 +61,7 @@ squash_install() { [[ $DRACUT_FIPS_MODE ]] && inst_libdir_file -o "libssl.so*" fi - hostonly="" instmods "loop" "squashfs" "overlay" + hostonly="" instmods "loop" "overlay" dracut_kernel_post # Install squash image init script. @@ -49,26 +74,9 @@ squash_install() { } squash_installpost() { - local _img="$squashdir"/squash-root.img - local _comp _file - - # shellcheck disable=SC2086 - if [[ $squash_compress ]]; then - if ! mksquashfs /dev/null "$DRACUT_TMPDIR"/.squash-test.img -no-progress -comp $squash_compress &> /dev/null; then - dwarn "mksquashfs doesn't support compressor '$squash_compress', failing back to default compressor." - else - _comp="$squash_compress" - fi - fi + local _file - # shellcheck disable=SC2086 - if ! mksquashfs "$initdir" "$_img" \ - -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \ - -no-progress ${_comp:+-comp $_comp} \ - -e "$squashdir" 1> /dev/null; then - dfatal "Failed making squash image" - exit 1 - fi + DRACUT_SQUASH_POST_INST=1 module_install "$(squash_get_handler)" # Rescue the dracut spec files so dracut rebuild and lsinitrd can work for _file in "$initdir"/usr/lib/dracut/*; do -- 2.42.0