From 59d8726dffd5c27300d0658d21245611afe275dd Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 19 Jan 2025 22:35:52 +0100 Subject: [PATCH 1/3] functions: Define list_filter_out function for filtering comma-sep lists Various kernel parameters are comma-separated lists, and we don't currently have any functions for manipulating them. Add the most urgently needed list_filter_out which will filter out matching items. Signed-off-by: Ben Hutchings --- scripts/functions | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/functions b/scripts/functions index 3d95f04..d0637c0 100644 --- a/scripts/functions +++ b/scripts/functions @@ -660,6 +660,31 @@ mountfs() ${type}_mount_fs "$1" } +# Filter matching items out of a comma-separated list. +# $1=list +# $2=pattern to match (may include shell wildcards) +list_filter_out() +{ + local pattern="$2" + local item result + local IFS=, + set -f + # shellcheck disable=SC2086 + set -- $1 + set +f + for item in "$@"; do + # shellcheck disable=SC2254 + case "$item" in + $pattern) + ;; + *) + result="${result:+$result,}${item}" + ;; + esac + done + echo "$result" +} + # Mount the root file system. It should be overridden by all # boot scripts. mountroot() From c1ad6a581fe6b32113b7d6704e2fe09a0d0d4a69 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 19 Jan 2025 22:38:27 +0100 Subject: [PATCH 2/3] init: Filter 'tmpfs' out of $ROOTFSTYPE The kernel now looks for 'tmpfs' in the value of the rootfstype parameter, and uses either ramfs or tmpfs for the initramfs depending on that. We should allow 'tmpfs' to appear, but not pass it down to the fsck and mount commands. So filter it out of the value of $ROOTFSTYPE. Signed-off-by: Ben Hutchings --- init | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/init b/init index 5752dd8..5552c64 100755 --- a/init +++ b/init @@ -101,7 +101,10 @@ for x in $(cat /proc/cmdline); do ROOTFLAGS="-o ${x#rootflags=}" ;; rootfstype=*) - ROOTFSTYPE="${x#rootfstype=}" + # Linux interprets 'rootfstype=*tmpfs*' to control the + # initramfs filesystem; we should remove 'tmpfs' from + # the list + ROOTFSTYPE="$(list_filter_out "${x#rootfstype=}" tmpfs)" ;; rootdelay=*) ROOTDELAY="${x#rootdelay=}" From 7b1093823aaf5b23bc9834ef54f467c6ebc455c2 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Fri, 5 Jul 2024 02:32:51 +0800 Subject: [PATCH 3/3] Fix resume device type check blkid will exit with success if it can gather information about the device, even if the device does not match the specified type. This fixes the device type check by getting the type value and testing it directly. Signed-off-by: Jeffery To [bwh: Keep checking that resolve_device and blkid are successful] Signed-off-by: Ben Hutchings --- hooks/resume | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/resume b/hooks/resume index 8ff84dd..d61fa89 100755 --- a/hooks/resume +++ b/hooks/resume @@ -24,7 +24,8 @@ if [ -n "$RESUME" ] && [ "$RESUME" != auto ]; then exit 0 fi if resume_dev_node="$(resolve_device "$RESUME")" && \ - blkid -p -n swap "$resume_dev_node" >/dev/null 2>&1; then + resume_dev_type=$(blkid -p -s TYPE -o value "$resume_dev_node") && \ + [ "$resume_dev_type" = swap ]; then exit 0 fi