]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(dmsquash-live): add support for dash
authorLaszlo Gombos <laszlo.gombos@gmail.com>
Mon, 15 Aug 2022 22:00:03 +0000 (22:00 +0000)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Tue, 25 Oct 2022 14:44:45 +0000 (16:44 +0200)
Using dash instead of bash saves about 0.5M initramfs size.

Co-authored-by: nabijaczleweli <nabijaczleweli@nabijaczleweli.xyz>
modules.d/90dmsquash-live/dmsquash-generator.sh
modules.d/90dmsquash-live/dmsquash-live-root.sh
modules.d/90dmsquash-live/module-setup.sh
test/TEST-16-DMSQUASH/test.sh

index fe25e9986430d9e1fb836cfaddc3804f03eaeee1..8e3dfe84836ddf2a8649ae9f4bd162f4f75c62e8 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
 
@@ -68,7 +68,7 @@ ROOTFLAGS="$(getarg rootflags)"
     else
         echo "What=/dev/mapper/live-rw"
         [ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}"
-        _dev=$'dev-mapper-live\\x2drw'
+        _dev='dev-mapper-live\x2drw'
     fi
 } > "$GENERATOR_DIR"/sysroot.mount
 
index 6d9ce42c8ab4e3f33bbc10eb0956876882b08d7e..b0ce506ebe582c422910ef5889286a109de5e769 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
 
@@ -35,7 +35,7 @@ getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
 
 # Take a path to a disk label and return the parent disk if it is a partition
 # Otherwise returns the original path
-function get_check_dev() {
+get_check_dev() {
     local _udevinfo
     dev_path="$(udevadm info -q path --name "$1")"
     _udevinfo="$(udevadm info -q property --path "${dev_path}")"
@@ -123,8 +123,15 @@ else
         # Symlinking /usr/bin/ntfs-3g as /sbin/mount.ntfs seems to boot
         # at the first glance, but ends with lots and lots of squashfs
         # errors, because systemd attempts to kill the ntfs-3g process?!
+        # See https://systemd.io/ROOT_STORAGE_DAEMONS/
         if [ -x "/usr/bin/ntfs-3g" ]; then
-            (exec -a @ntfs-3g ntfs-3g -o "${liverw:-ro}" "$livedev" /run/initramfs/live) | vwarn
+            (
+                ln -s /usr/bin/ntfs-3g /run/@ntfs-3g
+                (sleep 1 && rm /run/@ntfs-3g) &
+                # shellcheck disable=SC2123
+                PATH=/run
+                exec @ntfs-3g -o "${liverw:-ro}" "$livedev" /run/initramfs/live
+            ) | vwarn
         else
             die "Failed to mount block device of live image: Missing NTFS support"
             exit 1
@@ -222,25 +229,37 @@ do_live_overlay() {
         elif [ -n "$devspec" -a -n "$pathspec" ]; then
             [ -z "$m" ] \
                 && m='   Unable to find a persistent overlay; using a temporary one.'
-            m="$m"$'\n      All root filesystem changes will be lost on shutdown.'
-            m="$m"$'\n         Press [Enter] to continue.'
+            m="$m"'
+      All root filesystem changes will be lost on shutdown.
+         Press [Enter] to continue.'
             printf "\n\n\n\n%s\n\n\n" "${m}" > /dev/kmsg
             if [ -n "$DRACUT_SYSTEMD" ]; then
                 if type plymouth > /dev/null 2>&1 && plymouth --ping; then
                     if getargbool 0 rhgb || getargbool 0 splash; then
-                        m='>>>'$'\n''>>>'$'\n''>>>'$'\n\n\n'"$m"
-                        m="${m%n.*}"$'n.\n\n\n''<<<'$'\n''<<<'$'\n''<<<'
+                        m='>>>
+>>>
+>>>
+
+
+'"$m"
+                        m="${m%n.*}"'n.
+
+
+<<<
+<<<
+<<<'
                         plymouth display-message --text="${m}"
                     else
                         plymouth ask-question --prompt="${m}" --command=true
                     fi
                 else
-                    m=">>>${m//.[[:space:]]/.}  <<<"
+                    m=">>>$(printf '%s' "$m" | tr -d '\n')  <<<"
                     systemd-ask-password --timeout=0 "${m}"
                 fi
             else
                 type plymouth > /dev/null 2>&1 && plymouth --ping && plymouth --quit
-                read -s -r -p $'\n\n'"${m}" -n 1 _
+                printf '\n\n%s' "$m"
+                read -r _
             fi
         fi
         if [ -n "$overlayfs" ]; then
index b305ce1aa38f561b4a0ce090f555484ed966d9b6..cf3dfe5342de194d6ac914d9e3a09bf9ec78fbe6 100755 (executable)
@@ -11,7 +11,7 @@ check() {
 depends() {
     # if dmsetup is not installed, then we cannot support fedora/red hat
     # style live images
-    echo dm rootfs-block img-lib bash
+    echo dm rootfs-block img-lib
     return 0
 }
 
index 90c6a316761710800b550f000ebbea9db10c3072..3e88859bae6b0725dd4f601962df6d7b2a7f9270 100755 (executable)
@@ -136,7 +136,7 @@ test_setup() {
         inst_hook emergency 000 ./hard-off.sh
     )
     "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
-        --modules "dmsquash-live qemu" \
+        --modules "dash dmsquash-live qemu" \
         --omit "rngd" \
         --drivers "ext4 sd_mod" \
         --no-hostonly --no-hostonly-cmdline \