From 862ba52683834f87722cae7a6692a59d09271ec3 Mon Sep 17 00:00:00 2001 From: Laszlo Gombos Date: Mon, 15 Aug 2022 22:00:03 +0000 Subject: [PATCH] feat(dmsquash-live): add support for dash Using dash instead of bash saves about 0.5M initramfs size. Co-authored-by: nabijaczleweli --- .../90dmsquash-live/dmsquash-generator.sh | 4 +- .../90dmsquash-live/dmsquash-live-root.sh | 37 ++++++++++++++----- modules.d/90dmsquash-live/module-setup.sh | 2 +- test/TEST-16-DMSQUASH/test.sh | 2 +- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/modules.d/90dmsquash-live/dmsquash-generator.sh b/modules.d/90dmsquash-live/dmsquash-generator.sh index fe25e99864..8e3dfe8483 100755 --- a/modules.d/90dmsquash-live/dmsquash-generator.sh +++ b/modules.d/90dmsquash-live/dmsquash-generator.sh @@ -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 diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh index 6d9ce42c8a..b0ce506ebe 100755 --- a/modules.d/90dmsquash-live/dmsquash-live-root.sh +++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh @@ -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 diff --git a/modules.d/90dmsquash-live/module-setup.sh b/modules.d/90dmsquash-live/module-setup.sh index b305ce1aa3..cf3dfe5342 100755 --- a/modules.d/90dmsquash-live/module-setup.sh +++ b/modules.d/90dmsquash-live/module-setup.sh @@ -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 } diff --git a/test/TEST-16-DMSQUASH/test.sh b/test/TEST-16-DMSQUASH/test.sh index 90c6a31676..3e88859bae 100755 --- a/test/TEST-16-DMSQUASH/test.sh +++ b/test/TEST-16-DMSQUASH/test.sh @@ -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 \