]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(squash): add module 95squash-erofs
authorPhilipp Rudo <prudo@redhat.com>
Tue, 23 Jul 2024 15:42:33 +0000 (17:42 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 31 Jul 2024 11:41:26 +0000 (07:41 -0400)
Allow squashing the image in 99squash using erofs. Keep squashfs as
default to not change existing systems. I.e. only use erofs if the user
explicitly include 95squash-erofs or when the prereqs for squashfs are
missing.

Signed-off-by: Philipp Rudo <prudo@redhat.com>
modules.d/95squash-erofs/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-erofs/module-setup.sh b/modules.d/95squash-erofs/module-setup.sh
new file mode 100755 (executable)
index 0000000..71c2b67
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+check() {
+    require_binaries mkfs.erofs || return 1
+    require_kernel_modules erofs || return 1
+
+    return 255
+}
+
+depends() {
+    echo "squash"
+    return 0
+}
+
+erofs_install() {
+    hostonly="" instmods "erofs"
+}
+
+erofs_installpost() {
+    local _img="$squashdir/erofs-root.img"
+    local -a _erofs_args
+
+    _erofs_args+=("--exclude-path=$squashdir")
+    _erofs_args+=("-E" "fragments")
+
+    if [[ -n $squash_compress ]]; then
+        if mkfs.erofs "${_erofs_args[@]}" -z "$squash_compress" "$_img" "$initdir" &> /dev/null; then
+            return
+        fi
+        dwarn "mkfs.erofs doesn't support compressor '$squash_compress', failing back to default compressor."
+    fi
+
+    if ! mkfs.erofs "${_erofs_args[@]}" "$_img" "$initdir" &> /dev/null; then
+        dfatal "Failed making squash image"
+        exit 1
+    fi
+}
+
+install() {
+    if [[ $DRACUT_SQUASH_POST_INST ]]; then
+        erofs_installpost
+    else
+        dstdir="$squashdir" erofs_install
+    fi
+}
index 42a9a86fe97f202e83496080dc7795657d9cc58b..31a39cfd7f6a3f7bc2647cf0a10d75b0175937b8 100755 (executable)
@@ -13,15 +13,23 @@ grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \
 grep -q '^tmpfs /run tmpfs' /proc/self/mounts \
     || (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run)
 
+if [ -e /erofs-root.img ]; then
+    _fs=erofs
+    _img=erofs-root.img
+else
+    _fs=squashfs
+    _img=squashfs-root.img
+fi
+
 # Load required modules
 modprobe loop
-modprobe squashfs
+modprobe "$_fs"
 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 /squashfs-root.img /squash/root
+mount -t "$_fs" -o ro,loop /"$_img" /squash/root
 
 # Setup new root overlay
 mkdir /newroot
index 015944c2c67a5e5543c8116f467af6e2f1027ca7..5cbbec6394e02eadcafcb00b4ea7822da71f283e 100755 (executable)
@@ -18,7 +18,7 @@ depends() {
 squash_get_handler() {
     local _module _handler
 
-    for _module in squash-squashfs; do
+    for _module in squash-squashfs squash-erofs; do
         if dracut_module_included "$_module"; then
             _handler="$_module"
             break
@@ -28,6 +28,8 @@ squash_get_handler() {
     if [ -z "$_handler" ]; then
         if check_module "squash-squashfs"; then
             _handler="squash-squashfs"
+        elif check_module "squash-erofs"; then
+            _handler="squash-erofs"
         else
             dfatal "No valid handler for found"
             return 1