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.
This commit is contained in:
Steve Langasek 2023-04-14 22:47:09 -07:00
parent 4112488a44
commit 5e4b2d3cc3
2 changed files with 4 additions and 10 deletions

2
debian/control vendored
View File

@ -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,

View File

@ -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