boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

run.sh (2543B)


      1 #!/bin/sh
      2 # Boot the seed kernel + virtio-blk input/output disks in QEMU.
      3 #
      4 # Usage: ARCH=<aarch64|amd64|riscv64> ./run.sh [extra qemu args...]
      5 
      6 set -eu
      7 cd "$(dirname "$0")"
      8 
      9 ARCH=${ARCH:-aarch64}
     10 case "$ARCH" in
     11     aarch64) KERNEL=build/Image ;;
     12     amd64) KERNEL=build/kernel.elf ;;
     13     riscv64) KERNEL=build/kernel.elf ;;
     14     *) echo "unsupported ARCH=$ARCH" >&2; exit 2 ;;
     15 esac
     16 IN_IMG=build/in.img
     17 OUT_IMG=build/out.img
     18 
     19 [ -f "$KERNEL" ] || { echo "missing $KERNEL — run 'make' first"; exit 1; }
     20 [ -f "$IN_IMG" ] || { echo "missing $IN_IMG — run 'make' first"; exit 1; }
     21 
     22 # Pre-allocate a fresh 256 MiB output image (sparse) for each run; the
     23 # kernel writes a SEEDFS header at sector 0 unconditionally on exit.
     24 rm -f "$OUT_IMG"
     25 truncate -s 256M "$OUT_IMG"
     26 
     27 case "$ARCH" in
     28     aarch64)
     29         exec qemu-system-aarch64 \
     30             -machine virt,gic-version=3,accel=hvf \
     31             -cpu host \
     32             -m 2048M \
     33             -nographic \
     34             -no-reboot \
     35             -global virtio-mmio.force-legacy=false \
     36             -kernel "$KERNEL" \
     37             -drive file="$IN_IMG",if=none,format=raw,id=hd0,readonly=on \
     38             -device virtio-blk-device,drive=hd0 \
     39             -drive file="$OUT_IMG",if=none,format=raw,id=hd1 \
     40             -device virtio-blk-device,drive=hd1 \
     41             "$@"
     42         ;;
     43     amd64)
     44         exec qemu-system-x86_64 \
     45             -machine microvm,acpi=off,pic=off,pit=off,rtc=off,isa-serial=on,auto-kernel-cmdline=off \
     46             -cpu max \
     47             -m 2048M \
     48             -nodefaults \
     49             -display none \
     50             -serial stdio \
     51             -no-reboot \
     52             -global virtio-mmio.force-legacy=false \
     53             -device isa-debug-exit,iobase=0x501,iosize=2 \
     54             -kernel "$KERNEL" \
     55             -drive file="$IN_IMG",if=none,format=raw,id=hd0,readonly=on \
     56             -device virtio-blk-device,drive=hd0 \
     57             -drive file="$OUT_IMG",if=none,format=raw,id=hd1 \
     58             -device virtio-blk-device,drive=hd1 \
     59             "$@"
     60         ;;
     61     riscv64)
     62         exec qemu-system-riscv64 \
     63             -machine virt \
     64             -m 2048M \
     65             -nographic \
     66             -no-reboot \
     67             -global virtio-mmio.force-legacy=false \
     68             -kernel "$KERNEL" \
     69             -drive file="$IN_IMG",if=none,format=raw,id=hd0,readonly=on \
     70             -device virtio-blk-device,drive=hd0 \
     71             -drive file="$OUT_IMG",if=none,format=raw,id=hd1 \
     72             -device virtio-blk-device,drive=hd1 \
     73             "$@"
     74         ;;
     75 esac