From 744a2a1ac80bb905020e370e7f59d0eba702cb35 Mon Sep 17 00:00:00 2001 From: Petr Vandrovec Date: Thu, 19 Jan 2023 17:31:07 -0800 Subject: [PATCH] Read mounted partitions from /proc/self/mountinfo When system is booted without initrd, /proc/mounts root filesystem contains /dev/root, rather than specific device name (like /dev/sda1). That confuses os-prober logic for filesystem detection. On newer systems there is /proc/self/mountinfo, which contains major:minor device entry, which can be then looked up in sysfs to find device identifier. This does not affect systems that are using initrd, as initrd will provide correct device name when mounting the root filesystem. Signed-off-by: Petr Vandrovec --- common.sh | 16 ++++++++++++++++ linux-boot-prober | 2 +- os-prober | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common.sh b/common.sh index e1646d4..deab912 100644 --- a/common.sh +++ b/common.sh @@ -296,3 +296,19 @@ linux_mount_boot () { mountboot="$bootpart $mounted" } + +list_mounts() { + if [ -f /proc/self/mountinfo ]; then + local x dev mount devs found + found=: + while read -r x x dev x mount x; do + if [ -L "/sys/dev/block/$dev" ]; then + devs="/dev/`readlink \"/sys/dev/block/$dev\" | rev | cut -d/ -f1 | rev`" + printf '%s %s\n' "$(mapdevfs "$devs")" "$mount" + found="return 0" + fi + done < /proc/self/mountinfo + $found + fi + grep "^/dev/" /proc/mounts | parse_proc_mounts +} diff --git a/linux-boot-prober b/linux-boot-prober index e32dc84..7c85c2f 100755 --- a/linux-boot-prober +++ b/linux-boot-prober @@ -6,7 +6,7 @@ set -e newns "$@" require_tmpdir -grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true +list_mounts >"$OS_PROBER_TMP/mounted-map" || true partition="$1" diff --git a/os-prober b/os-prober index 0d73ade..844d737 100755 --- a/os-prober +++ b/os-prober @@ -120,7 +120,7 @@ done # We need to properly canonicalize partitions with mount points and partitions # used in RAID -grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true +list_mounts >"$OS_PROBER_TMP/mounted-map" || true : >"$OS_PROBER_TMP/swaps-map" if [ -f /proc/swaps ]; then grep "^/dev/" /proc/swaps | parse_proc_swaps >"$OS_PROBER_TMP/swaps-map" || true -- 2.39.0