#!/bin/bash

# QEMU start script for illumos riscv64
# only tested on QEMU 6.2.0

BIOSBIN=fw_jump.bin
BOOTLDR=inetboot_virt.bin
BOOTARG="-D /soc/virtio_mmio@10007000"
DISKIMG=root_zfs-illumos-20230505-riscv64.img

qemu-system-riscv64 \
    -nographic -machine virt \
    -smp 4 -m 2G \
    -bios ${BIOSBIN} \
    -netdev user,id=net0 \
    -device virtio-net-device,netdev=net0 \
    -drive file=${DISKIMG},format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0 \
    -kernel ${BOOTLDR} \
    -append ${BOOTARG}

# files needed: this script, and
## fw_jump.bin
## inetboot_virt.bin
## root_zfs-illumos-20230505-riscv64.img.zst
# uncompress the rootfs image with zstd:
## zstd -d root_zfs-illumos-20230505-riscv64.img.zst
## chmod +x illumos-qemu-riscv64.sh
## bash ./illumos-qemu-riscv64.sh
# user is root with empty password
# just hit enter when login prompt for password
# enjoy playing around!

# to get network connection:
## ipadm create-if -t platmac0
## ipadm create-addr -t -T dhcp platmac0/v4
# to have a working DNS
## echo "nameserver 10.0.2.3" > /etc/resolv.conf
## mv /etc/nsswitch.conf /etc/nsswitch.conf.bak
## cp /etc/nsswitch.dns /etc/nsswitch.conf
# ping does not work correctly with such DNS
# wget works well
# update time and date to have better experience
# for example 15:59 on 30. Dec. 2022
## date -u 123015592022
