From 1377e903b864673138908165572a18933400e8eb Mon Sep 17 00:00:00 2001 From: Vasilis Tsiligiannis Date: Thu, 4 Jan 2024 13:05:51 +0200 Subject: [PATCH] Ensure loop device partition nodes are created (#741) Although the loop block device is created before attaching the image to it, the devices for the partition that the image contains are still not created. This patch creates those devices as well, when they are not already available. Fixes #482 Signed-off-by: Vasilis Tsiligiannis --- export-image/prerun.sh | 1 + export-noobs/prerun.sh | 1 + scripts/common | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/export-image/prerun.sh b/export-image/prerun.sh index a5f94e9..d042c6a 100755 --- a/export-image/prerun.sh +++ b/export-image/prerun.sh @@ -46,6 +46,7 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then fi done + ensure_loopdev_partitions "$LOOP_DEV" BOOT_DEV="${LOOP_DEV}p1" ROOT_DEV="${LOOP_DEV}p2" diff --git a/export-noobs/prerun.sh b/export-noobs/prerun.sh index 6282836..80cbb8e 100755 --- a/export-noobs/prerun.sh +++ b/export-noobs/prerun.sh @@ -22,6 +22,7 @@ until ensure_next_loopdev && LOOP_DEV="$(losetup --show --find --partscan "$IMG_ fi done +ensure_loopdev_partitions "$LOOP_DEV" BOOT_DEV="${LOOP_DEV}p1" ROOT_DEV="${LOOP_DEV}p2" diff --git a/scripts/common b/scripts/common index 74c7938..cda5551 100644 --- a/scripts/common +++ b/scripts/common @@ -110,3 +110,17 @@ ensure_next_loopdev() { [[ -b "$loopdev" ]] || mknod "$loopdev" b 7 "$loopmaj" } export -f ensure_next_loopdev + +ensure_loopdev_partitions() { + local line + local partition + local majmin + lsblk -r -n -o "NAME,MAJ:MIN" "$1" | grep -v "^${1#/dev/} " | while read -r line; do + partition="${line%% *}" + majmin="${line#* }" + if [ ! -b "/dev/$partition" ]; then + mknod "/dev/$partition" b "${majmin%:*}" "${majmin#*:}" + fi + done +} +export -f ensure_loopdev_partitions