From 24c5a452023b43540686a45b0b6e2b9f1a6257df Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sat, 5 Nov 2022 14:59:57 +0100 Subject: [PATCH] make_mirror.sh: switch from extlinux to grub-efi to support arm64 --- make_mirror.sh | 65 ++++++++++++++++++++++++++++---------------------- run_qemu.sh | 25 +++++++++++++++++-- 2 files changed, 59 insertions(+), 31 deletions(-) diff --git a/make_mirror.sh b/make_mirror.sh index bcca116..1c68987 100755 --- a/make_mirror.sh +++ b/make_mirror.sh @@ -465,12 +465,10 @@ cleanuptmpdir() { if [ ! -e "$tmpdir" ]; then return fi - for f in "$tmpdir/extlinux.conf" \ - "$tmpdir/worker.sh" \ + for f in "$tmpdir/worker.sh" \ "$tmpdir/mini-httpd" "$tmpdir/hosts" \ "$tmpdir/debian-chroot.tar" \ - "$tmpdir/mmdebstrap.service" \ - "$tmpdir/debian-$DEFAULT_DIST.img"; do + "$tmpdir/mmdebstrap.service"; do if [ ! -e "$f" ]; then echo "does not exist: $f" >&2 continue @@ -484,12 +482,12 @@ export SOURCE_DATE_EPOCH=$(date --date="$(grep-dctrl -s Date -n '' "$newmirrordi if [ "$HAVE_QEMU" = "yes" ]; then case "$HOSTARCH" in - amd64|i386) + amd64|i386|arm64) # okay ;; *) - echo "qemu support is only available on amd64 and i386" >&2 - echo "because syslinux is only available on those arches" >&2 + echo "qemu support is only available on amd64, i386 and arm64" >&2 + echo "because grub is only available on those arches" >&2 exit 1 ;; esac @@ -503,7 +501,7 @@ if [ "$HAVE_QEMU" = "yes" ]; then tmpdir="$(mktemp -d)" trap "cleanuptmpdir; cleanup_newcachedir" EXIT INT TERM - pkgs=perl-doc,systemd-sysv,perl,arch-test,fakechroot,fakeroot,mount,uidmap,qemu-user-static,binfmt-support,qemu-user,dpkg-dev,mini-httpd,libdevel-cover-perl,libtemplate-perl,debootstrap,procps,apt-cudf,aspcud,python3,libcap2-bin,gpg,debootstrap,distro-info-data,iproute2,ubuntu-keyring,apt-utils + pkgs=perl-doc,systemd-sysv,perl,arch-test,fakechroot,fakeroot,mount,uidmap,qemu-user-static,binfmt-support,qemu-user,dpkg-dev,mini-httpd,libdevel-cover-perl,libtemplate-perl,debootstrap,procps,apt-cudf,aspcud,python3,libcap2-bin,gpg,debootstrap,distro-info-data,iproute2,ubuntu-keyring,apt-utils,grub-efi if [ "$DEFAULT_DIST" != "oldstable" ]; then pkgs="$pkgs,squashfs-tools-ng,genext2fs" fi @@ -540,15 +538,6 @@ if [ "$HAVE_QEMU" = "yes" ]; then --aptopt='Acquire::Retries "5"' \ $DEFAULT_DIST - "$mirror" > "$tmpdir/debian-chroot.tar" - cat << END > "$tmpdir/extlinux.conf" -default linux -timeout 0 - -label linux -kernel /vmlinuz -append initrd=/initrd.img root=/dev/vda1 rw console=tty0 console=ttyS0,115200n8 -serial 0 115200 -END cat << END > "$tmpdir/mmdebstrap.service" [Unit] Description=mmdebstrap worker script @@ -631,13 +620,30 @@ END if [ -z ${DISK_SIZE+x} ]; then DISK_SIZE=10G fi - guestfish -N "$tmpdir/debian-$DEFAULT_DIST.img"=disk:$DISK_SIZE -- \ - part-disk /dev/sda mbr : \ - mkfs ext2 /dev/sda1 : \ - mount /dev/sda1 / : \ - tar-in "$tmpdir/debian-chroot.tar" / : \ + case "$HOSTARCH" in + amd64) GRUB_TARGET=x86_64-efi;; + i386) GRUB_TARGET=i386-efi;; + arm64) GRUB_TARGET=arm64-efi;; + esac + case "$HOSTARCH" in + arm64) SERIAL="loglevel=3 console=tty0 console=ttyAMA0,115200n8" ;; + *) SERIAL="loglevel=3 console=tty0 console=ttyS0,115200n8" ;; + esac + guestfish -- \ + disk-create "$newcachedir/debian-$DEFAULT_DIST.qcow" qcow2 "$DISK_SIZE" : \ + add-drive "$newcachedir/debian-$DEFAULT_DIST.qcow" format:qcow2 : \ + launch : \ + part-init /dev/sda gpt : \ + part-add /dev/sda primary 8192 262144 : \ + part-add /dev/sda primary 262145 -34 : \ + part-set-gpt-type /dev/sda 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B : \ + mkfs ext2 /dev/sda2 : \ + mount /dev/sda2 / : \ + tar-in "$tmpdir/debian-chroot.tar" / xattrs:true : \ + mkdir-p /boot/efi : \ + mkfs vfat /dev/sda1 : \ + mount /dev/sda1 /boot/efi : \ command /sbin/ldconfig : \ - copy-in "$tmpdir/extlinux.conf" / : \ mkdir-p /etc/systemd/system/multi-user.target.wants : \ ln-s ../mmdebstrap.service /etc/systemd/system/multi-user.target.wants/mmdebstrap.service : \ copy-in "$tmpdir/mmdebstrap.service" /etc/systemd/system/ : \ @@ -645,15 +651,16 @@ END copy-in "$tmpdir/mini-httpd" /etc/default : \ copy-in "$tmpdir/hosts" /etc/ : \ touch /mmdebstrap-testenv : \ - upload /usr/lib/EXTLINUX/mbr.bin /mbr.bin : \ - copy-file-to-device /mbr.bin /dev/sda size:440 : \ - rm /mbr.bin : \ - extlinux / : \ + command "sh -c 'echo UUID=\$(blkid -c /dev/null -o value -s UUID /dev/sda2) / ext4 errors=remount-ro 0 1 > /etc/fstab'" : \ + command "sh -c 'echo UUID=\$(blkid -c /dev/null -o value -s UUID /dev/sda1) /boot/efi vfat errors=remount-ro 0 2 >> /etc/fstab'" : \ + command "sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT=/GRUB_CMDLINE_LINUX_DEFAULT=\"biosdevname=0 net.ifnames=0 consoleblank=0 rw $SERIAL\"/' /etc/default/grub" : \ + command "update-initramfs -u" : \ + command "grub-mkconfig -o /boot/grub/grub.cfg" : \ + command "grub-install /dev/sda --target=$GRUB_TARGET --no-nvram --force-extra-removable --no-floppy --modules=part_gpt --grub-mkdevicemap=/boot/grub/device.map" : \ sync : \ + umount /boot/efi : \ umount / : \ - part-set-bootable /dev/sda 1 true : \ shutdown - qemu-img convert -O qcow2 "$tmpdir/debian-$DEFAULT_DIST.img" "$newcachedir/debian-$DEFAULT_DIST.qcow" cleanuptmpdir trap "cleanup_newcachedir" EXIT INT TERM fi diff --git a/run_qemu.sh b/run_qemu.sh index faa4f3a..edae273 100755 --- a/run_qemu.sh +++ b/run_qemu.sh @@ -25,6 +25,26 @@ cleanup() { trap cleanup INT TERM EXIT +ARCH=$(dpkg --print-architecture) +case $ARCH in + i386) + MACHINE="accel=kvm:tcg" + CODE="/usr/share/OVMF/OVMF32_CODE_4M.secboot.fd" + QEMUARCH="i386" + ;; + amd64) + MACHINE="accel=kvm:tcg" + CODE="/usr/share/OVMF/OVMF_CODE.fd" + QEMUARCH="x86_64" + ;; + arm64) + MACHINE="type=virt,gic-version=host,accel=kvm" + CODE="/usr/share/AAVMF/AAVMF_CODE.fd,readonly" + QEMUARCH="aarch64" + ;; + *) echo "qemu kvm not supported on $ARCH" >&2;; +esac + # the path to debian-$DEFAULT_DIST.qcow must be absolute or otherwise qemu will # look for the path relative to debian-$DEFAULT_DIST-overlay.qcow qemu-img create -f qcow2 -b "$(realpath $cachedir)/debian-$DEFAULT_DIST.qcow" -F qcow2 "$tmpdir/debian-$DEFAULT_DIST-overlay.qcow" @@ -34,15 +54,16 @@ qemu-img create -f qcow2 -b "$(realpath $cachedir)/debian-$DEFAULT_DIST.qcow" -F # or this (quit with ctrl+q): # socat stdin,raw,echo=0,escape=0x11 unix-connect:/tmp/ttyS0 ret=0 -timeout --foreground 20m qemu-system-x86_64 \ +timeout --foreground 20m qemu-system-"$QEMUARCH" \ -cpu host \ -no-user-config \ - -M accel=kvm:tcg -m 4G -nographic \ + -M "$MACHINE" -m 4G -nographic \ -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \ -monitor unix:/tmp/monitor,server,nowait \ -serial unix:/tmp/ttyS0,server,nowait \ -serial unix:/tmp/ttyS1,server,nowait \ -net nic,model=virtio -net user \ + -drive if=pflash,format=raw,unit=0,read-only,file="$CODE" \ -virtfs local,id=mmdebstrap,path="$(pwd)/shared",security_model=none,mount_tag=mmdebstrap \ -drive file="$tmpdir/debian-$DEFAULT_DIST-overlay.qcow",cache=unsafe,index=0,if=virtio \ >"$tmpdir/log" 2>&1 || ret=$?