#!/bin/sh
#
# From:
#   https://gist.github.com/KunoiSayami/934c7690dcf357f42537562dbdf90b56
#
# Download files:
#   wget https://ftp.debian.org/debian/dists/Debian12.8/main/installer-armhf/current/images/netboot/initrd.gz
#   wget https://ftp.debian.org/debian/dists/Debian12.8/main/installer-armhf/current/images/netboot/vmlinuz
#
# Create disk:
#   qemu-img create -f qcow2 rootfs.qcow 16G
#
qemu-system-arm \
    -nographic \
    -machine virt \
    -m 2G \
    -smp 4 \
    -device virtio-blk-device,drive=disk \
    -drive file=rootfs.qcow,if=none,id=disk \
    -device virtio-net-device,netdev=net \
    -netdev user,id=net,hostfwd=tcp::2222-:22 \
    -kernel vmlinuz \
    -initrd initrd.gz \
    -append "ip=dhcp, console=ttyAMA0"

# On linux, extract kernel and initrd files:
#   sudo apt install qemu-utils
#   sudo modprobe nbd max_part=8
#   sudo qemu-nbd --connect=/dev/nbd0 ./rootfs.qcow
#   sudo mount /dev/nbd0p1 /mnt
#   cp /mnt/vmlinuz-*-armmp-lpae .
#   cp /mnt/initrd.img-*-armmp-lpae .
#   sudo umount /mnt
#   sudo qemu-nbd --disconnect /dev/nbd0
