From 5e4b2d3cc35d2a89c4e05c55021c0d934596e8e0 Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Fri, 14 Apr 2023 22:47:09 -0700 Subject: [PATCH] Use losetup instead of kpartx to set up loopback partitions kpartx on riscv64 appears to be racy. Rather than trying to debug these fraught races somewhere between udev and libdevmapper, we can use losetup which should be simpler and less error-prone. --- debian/control | 2 +- live-build/functions | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/debian/control b/debian/control index c8c78a76..9578e589 100644 --- a/debian/control +++ b/debian/control @@ -22,11 +22,11 @@ Depends: ${misc:Depends}, git, gnupg, grep-dctrl, - kpartx, live-build (>= 3.0~a57-1ubuntu31~), lsb-release, lzma, make, + mount, parted, procps, python3, diff --git a/live-build/functions b/live-build/functions index f16c9445..c8695486 100644 --- a/live-build/functions +++ b/live-build/functions @@ -12,16 +12,13 @@ loop_raw= backing_img= clean_loops() { - local kpartx_ret - local kpartx_stdout - if [ -n "${backing_img}" ]; then # If something just finished writing to the device or a # partition (e.g. the zerofree in umount_partition) udev might # still be processing the device. udevadm settle sync - kpartx -v -d "${backing_img}" + losetup -v -d "${backing_img}" unset backing_img fi @@ -65,18 +62,15 @@ mount_image() { trap clean_loops EXIT backing_img="$1" local rootpart="$2" - kpartx_mapping="$(kpartx -s -v -a ${backing_img})" + loop_device=$(losetup --show -f -P -v ${backing_img}) - # Find the loop device - loop_p1="$(echo -e ${kpartx_mapping} | head -n1 | awk '{print$3}')" - loop_device="/dev/${loop_p1%p[0-9]*}" if [ ! -b ${loop_device} ]; then echo "unable to find loop device for ${backing_img}" exit 1 fi # Find the rootfs location - rootfs_dev_mapper="/dev/mapper/${loop_p1%%[0-9]}${rootpart}" + rootfs_dev_mapper="/dev/mapper/${loop_device}p${rootpart}" if [ ! -b "${rootfs_dev_mapper}" ]; then echo "${rootfs_dev_mapper} is not a block device"; exit 1