]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(squash): split 95squash-squashfs from 99squash
authorPhilipp Rudo <prudo@redhat.com>
Tue, 23 Jul 2024 14:39:13 +0000 (16:39 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 31 Jul 2024 11:41:26 +0000 (07:41 -0400)
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 <prudo@redhat.com>
modules.d/95squash-squashfs/module-setup.sh [new file with mode: 0755]
modules.d/99squash/init-squash.sh
modules.d/99squash/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 (executable)
index 0000000..8397370
--- /dev/null
@@ -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
+}
index 59769f621827c72cb7e77a71d3e85492f4bedc21..42a9a86fe97f202e83496080dc7795657d9cc58b 100755 (executable)
@@ -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
index 96d097aff767ffa43bacfe8cb37533cf004f22d8..015944c2c67a5e5543c8116f467af6e2f1027ca7 100755 (executable)
@@ -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