From 582c081675996b72f63ed50e4e956a838612876c Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Fri, 26 May 2023 09:41:32 -0700 Subject: [PATCH 1/3] Use losetup instead of kpartx to resolve race conditions in riscv64 image builds. --- debian/changelog | 7 +++++ debian/control | 1 + .../buildd/hooks/02-disk-image-uefi.binary | 2 +- live-build/functions | 18 ++++-------- .../hooks.d/base/disk-image-ppc64el.binary | 2 +- .../hooks.d/base/disk-image-uefi.binary | 28 +++++++++---------- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/debian/changelog b/debian/changelog index 87a5e4bc..cb1abc0d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +livecd-rootfs (2.765.32) UNRELEASED; urgency=medium + + * Use losetup instead of kpartx to resolve race conditions in riscv64 + image builds. + + -- Steve Langasek Sun, 03 Dec 2023 22:03:36 -0800 + livecd-rootfs (2.765.31) jammy; urgency=medium [ John Chittum ] diff --git a/debian/control b/debian/control index 4aa37bb9..115870fe 100644 --- a/debian/control +++ b/debian/control @@ -27,6 +27,7 @@ Depends: ${misc:Depends}, lsb-release, lzma, make, + mount, parted, procps, python3, diff --git a/live-build/buildd/hooks/02-disk-image-uefi.binary b/live-build/buildd/hooks/02-disk-image-uefi.binary index 55bc73a9..e4a5f8f9 100755 --- a/live-build/buildd/hooks/02-disk-image-uefi.binary +++ b/live-build/buildd/hooks/02-disk-image-uefi.binary @@ -41,7 +41,7 @@ create_partitions() { } create_and_mount_uefi_partition() { - uefi_dev="/dev/mapper${loop_device///dev/}p15" + uefi_dev="${loop_device}p15" mountpoint="$1" mkfs.vfat -F 32 -n UEFI "${uefi_dev}" diff --git a/live-build/functions b/live-build/functions index 1997110d..049a1ca2 100644 --- a/live-build/functions +++ b/live-build/functions @@ -10,16 +10,13 @@ loop_raw= backing_img= clean_loops() { - local kpartx_ret - local kpartx_stdout - - if [ -n "${backing_img}" ]; then + if [ -n "${loop_device}" ]; 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 "${loop_device}" unset backing_img fi @@ -63,18 +60,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="${loop_device}p${rootpart}" if [ ! -b "${rootfs_dev_mapper}" ]; then echo "${rootfs_dev_mapper} is not a block device"; exit 1 @@ -211,7 +205,7 @@ mount_disk_image() { mount_image ${disk_image} 1 mount_partition "${rootfs_dev_mapper}" $mountpoint - local uefi_dev="/dev/mapper${loop_device///dev/}p15" + local uefi_dev="${loop_device}p15" if [ -b ${uefi_dev} -a -e $mountpoint/boot/efi ]; then mount "${uefi_dev}" $mountpoint/boot/efi fi @@ -252,7 +246,7 @@ umount_partition() { umount_disk_image() { mountpoint="$1" - local uefi_dev="/dev/mapper${loop_device///dev/}p15" + local uefi_dev="${loop_device}p15" if [ -e "$mountpoint/boot/efi" -a -b "$uefi_dev" ]; then # zero fill free space in UEFI partition cat < /dev/zero > "$mountpoint/boot/efi/bloat_file" 2> /dev/null || true diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image-ppc64el.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image-ppc64el.binary index dc87a361..b5b7cffc 100755 --- a/live-build/ubuntu-cpc/hooks.d/base/disk-image-ppc64el.binary +++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image-ppc64el.binary @@ -49,7 +49,7 @@ GRUB_TIMEOUT=0 # Set the default commandline GRUB_CMDLINE_LINUX_DEFAULT="console=hvc0 earlyprintk" EOF - prep_partition="/dev/mapper${loop_device///dev/}p2" + prep_partition="${loop_device}p2" chroot mountpoint grub-install "${prep_partition}" \ --no-nvram \ --boot-directory=/boot \ diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary index df8cb4af..76e67ef1 100755 --- a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary +++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary @@ -166,7 +166,7 @@ create_partitions() { } create_and_mount_uefi_partition() { - uefi_dev="/dev/mapper${loop_device///dev/}p15" + uefi_dev="${loop_device}p15" mountpoint="$1" mkfs.vfat -F 32 -n UEFI "${uefi_dev}" @@ -203,7 +203,7 @@ install_grub() { # Server preinstalled image # Setup cidata sample data & nocloud fallback # Allows login on first boot with or without metadata - cidata_dev="/dev/mapper${loop_device///dev/}p14" + cidata_dev="${loop_device}p14" setup_cidata "${cidata_dev}" setup_cinocloud mountpoint fi @@ -215,7 +215,7 @@ install_grub() { # Server preinstalled image # Setup cidata sample data & nocloud fallback # Allows login on first boot with or without metadata - cidata_dev="/dev/mapper${loop_device///dev/}p14" + cidata_dev="${loop_device}p14" setup_cidata "${cidata_dev}" setup_cinocloud mountpoint fi @@ -227,7 +227,7 @@ install_grub() { # Server preinstalled image # Setup cidata sample data & nocloud fallback # Allows login on first boot with or without metadata - cidata_dev="/dev/mapper${loop_device///dev/}p13" + cidata_dev="${loop_device}p13" setup_cidata "${cidata_dev}" setup_cinocloud mountpoint fi @@ -253,10 +253,10 @@ install_grub() { efi_target=riscv64-efi # The real U-Boot chroot mountpoint apt-get install -qqy u-boot-microchip - loader="/dev/mapper${loop_device///dev/}p13" + loader="${loop_device}p13" dd if=mountpoint/usr/lib/u-boot/microchip_icicle/u-boot.payload of=$loader # Provide end-user modifyable CIDATA - cidata_dev="/dev/mapper${loop_device///dev/}p12" + cidata_dev="${loop_device}p12" setup_cidata "${cidata_dev}" # Provide stock nocloud datasource # Allow interactive login on baremetal board, @@ -297,15 +297,15 @@ install_grub() { # nezha-boot0 is actually compatible with the LicheeRV boards (and probably other D1-based boards) chroot mountpoint apt-get install -qqy nezha-boot0 # FSBL, which gets U-Boot SPL - loader1="/dev/mapper${loop_device///dev/}p13" + loader1="${loop_device}p13" dd if=mountpoint/usr/lib/u-boot/nezha/boot0_sdcard_sun20iw1p1.bin of=$loader1 # The real U-Boot # u-boot-nezha actually contains both the LicheeRV and the Nezha boards support chroot mountpoint apt-get install -qqy u-boot-nezha - loader2="/dev/mapper${loop_device///dev/}p14" + loader2="${loop_device}p14" dd if=mountpoint/usr/lib/u-boot/${SUBARCH}/u-boot.toc1 of=$loader2 # Provide end-user modifyable CIDATA - cidata_dev="/dev/mapper${loop_device///dev/}p12" + cidata_dev="${loop_device}p12" setup_cidata "${cidata_dev}" # Provide stock nocloud datasource # Allow interactive login on baremetal SiFive board, @@ -331,7 +331,7 @@ install_grub() { efi_target=riscv64-efi # factory u-boot requires a p3 partition with /boot/uEnv.txt file - uenv_dev="/dev/mapper${loop_device///dev/}p3" + uenv_dev="${loop_device}p3" mkfs.ext4 "${uenv_dev}" uenv_mnt_dir=`mktemp -d uenvXXX` mount "${uenv_dev}" "${uenv_mnt_dir}" @@ -359,7 +359,7 @@ EOF umount "${uenv_mnt_dir}" rmdir "${uenv_mnt_dir}" # Provide end-user modifyable CIDATA - cidata_dev="/dev/mapper${loop_device///dev/}p12" + cidata_dev="${loop_device}p12" setup_cidata "${cidata_dev}" # Provide stock nocloud datasource # Allow interactive login on baremetal SiFive board, @@ -376,13 +376,13 @@ EOF fi chroot mountpoint apt-get install -qqy u-boot-sifive # FSBL, which gets U-Boot SPL - loader1="/dev/mapper${loop_device///dev/}p13" + loader1="${loop_device}p13" # The real U-Boot - loader2="/dev/mapper${loop_device///dev/}p14" + loader2="${loop_device}p14" dd if=mountpoint/usr/lib/u-boot/${u_boot_arch}/u-boot-spl.bin of=$loader1 dd if=mountpoint/usr/lib/u-boot/${u_boot_arch}/u-boot.itb of=$loader2 # Provide end-user modifyable CIDATA - cidata_dev="/dev/mapper${loop_device///dev/}p12" + cidata_dev="${loop_device}p12" setup_cidata "${cidata_dev}" # Provide stock nocloud datasource # Allow interactive login on baremetal SiFive board, From fe04dedbf8cca3a33edcf8556738481d614893ac Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Mon, 4 Dec 2023 08:33:42 -0800 Subject: [PATCH 2/3] Document in debian/control that kpartx dep is for CPC --- debian/control | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/control b/debian/control index 115870fe..613cc069 100644 --- a/debian/control +++ b/debian/control @@ -22,6 +22,8 @@ Depends: ${misc:Depends}, git, gnupg, grep-dctrl, + # only needed now for CPC sauce hooks and should be dropped + # when they no longer require it kpartx, live-build (>= 3.0~a57-1ubuntu31~), lsb-release, From f45bf216365591c065a73d4a861ab8e44d4c3e79 Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Wed, 6 Dec 2023 10:59:00 -0800 Subject: [PATCH 3/3] Include bug ref in changelog. Bug-Ubuntu: https://bugs.launchpad.net/bugs/2045797 --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index cb1abc0d..81ad51d4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,7 @@ livecd-rootfs (2.765.32) UNRELEASED; urgency=medium * Use losetup instead of kpartx to resolve race conditions in riscv64 - image builds. + image builds. LP: #2045797. -- Steve Langasek Sun, 03 Dec 2023 22:03:36 -0800