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.
losetup-not-kpartx
Steve Langasek 2 years ago
parent 4112488a44
commit 5e4b2d3cc3

2
debian/control vendored

@ -22,11 +22,11 @@ Depends: ${misc:Depends},
git, git,
gnupg, gnupg,
grep-dctrl, grep-dctrl,
kpartx,
live-build (>= 3.0~a57-1ubuntu31~), live-build (>= 3.0~a57-1ubuntu31~),
lsb-release, lsb-release,
lzma, lzma,
make, make,
mount,
parted, parted,
procps, procps,
python3, python3,

@ -12,16 +12,13 @@ loop_raw=
backing_img= backing_img=
clean_loops() { clean_loops() {
local kpartx_ret
local kpartx_stdout
if [ -n "${backing_img}" ]; then if [ -n "${backing_img}" ]; then
# If something just finished writing to the device or a # If something just finished writing to the device or a
# partition (e.g. the zerofree in umount_partition) udev might # partition (e.g. the zerofree in umount_partition) udev might
# still be processing the device. # still be processing the device.
udevadm settle udevadm settle
sync sync
kpartx -v -d "${backing_img}" losetup -v -d "${backing_img}"
unset backing_img unset backing_img
fi fi
@ -65,18 +62,15 @@ mount_image() {
trap clean_loops EXIT trap clean_loops EXIT
backing_img="$1" backing_img="$1"
local rootpart="$2" 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 if [ ! -b ${loop_device} ]; then
echo "unable to find loop device for ${backing_img}" echo "unable to find loop device for ${backing_img}"
exit 1 exit 1
fi fi
# Find the rootfs location # 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 if [ ! -b "${rootfs_dev_mapper}" ]; then
echo "${rootfs_dev_mapper} is not a block device"; echo "${rootfs_dev_mapper} is not a block device";
exit 1 exit 1

Loading…
Cancel
Save