RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / scripts / run-qemu.sh
1472 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash
# Boot the Foundry OS image interactively on the pinned Rustbelt kernel:
# a QEMU window (or add NOGRAPHIC=1 for serial only), our image as disk 0
# (B:), the kernel's test disks as C:, D:, E:. Same devices as the kernel's
# `cargo run`. The hvc0 console is on the unix socket OUT/hvc0.sock:
#   socat - UNIX-CONNECT:out/hvc0.sock     (then `getty /dev/hvc0 &` in Foundry)
#
# Usage: scripts/run-qemu.sh IMAGE KERNEL_BOOTIMAGE KERNEL_TARGET OUT_DIR
set -euo pipefail
cd "$(dirname "$0")/.."
IMAGE=$1 IMG=$2 KT=$3 OUT=$4
display=()
[ -n "${NOGRAPHIC:-}" ] && display=(-display none)
exec qemu-system-x86_64 -smp 4 -cpu "${QEMU_CPU:-max}" \
    -pidfile "$OUT/qemu-run.pid" \
    -drive format=raw,file="$IMG",snapshot=on \
    -drive file="$IMAGE",format=raw,if=virtio,snapshot=on \
    -drive file="$KT/ext2.img",format=raw,if=virtio,snapshot=on \
    -drive file="$KT/exfat.img",format=raw,if=virtio,snapshot=on \
    -drive file="$KT/btrfs.img",format=raw,if=virtio,snapshot=on \
    -netdev "user,id=net0,guestfwd=tcp:10.0.2.100:80-cmd:sh scripts/http-reply.sh,guestfwd=tcp:10.0.2.100:7-cmd:cat,hostfwd=tcp:127.0.0.1:5580-:80" \
    -device virtio-net-pci,netdev=net0 \
    -vga none -device virtio-vga -device virtio-rng-pci \
    -device virtio-serial-pci -device virtconsole,chardev=hvc \
    -chardev "socket,id=hvc,path=$OUT/hvc0.sock,server=on,wait=off" \
    -device isa-debug-exit,iobase=0xf4,iosize=0x04 \
    -serial stdio "${display[@]}"