From: phoebe-lab local fix
Subject: [PATCH] builds.sr.ht-images ubuntu/genimg: fix nbd settle race + host chown
Two independent fixes for the upstream `images/ubuntu/genimg` script as shipped
in the `builds.sr.ht-images` Alpine package (last verified against 0.103.12-r0).
Both bugs make image generation fail on any host that doesn't happen to satisfy
their hidden assumptions.
1) After `qemu-nbd --connect`, the kernel hasn't picked up the device size yet,
so the immediate `dd if=mbr.bin of=/dev/nbd0` fails with "No space left on
device". The sibling `debian/genimg` already handles this with a partprobe
loop; ubuntu's variant is missing it. Verbatim copy of the debian fix.
2) `chown build:build /mnt/home/build/.gitconfig` runs on the *host*, not in
the chroot. There's no host user named `build` on a typical Arch/Debian
builder VM, so the script aborts at the very end after 5+ min of debootstrap
work. Routing the chown through `run_root` (the existing chroot helper used
everywhere else in the file) puts it where the user actually exists.
Apply when refreshing the apk recipe tree on the image-builder host:
cd /var/lib/images
patch -p0 < builds-images-ubuntu-genimg.patch
--- a/ubuntu/genimg
+++ b/ubuntu/genimg
@@ -35,6 +35,7 @@
qemu-img create -f qcow2 $arch/root.img.qcow2 32G
modprobe nbd max_part=16
qemu-nbd --connect=/dev/nbd0 $arch/root.img.qcow2
+for i in 1 2 3 4 5; do sleep 0.$i; partprobe /dev/nbd0 && break; done
trap cleanup EXIT
if [ "$arch" = "amd64" ]
@@ -163,7 +164,7 @@
name = builds.sr.ht
email = builds@sr.ht
EOF
-chown build:build /mnt/home/build/.gitconfig
+run_root chown build:build /home/build/.gitconfig
if [ "$arch" != "amd64" ]
then