3 # Copyright (C) 2020 David Runge <dvzrv@archlinux.org>
5 # SPDX-License-Identifier: GPL-3.0-or-later
7 # A simple script to run an archiso image using qemu. The image can be booted
12 # - edk2-ovmf (when UEFI booting)
22 -b set boot type to 'bios' (default)
24 -i [image] image to boot into
25 -s use secure boot (only relevant when using UEFI)
26 -u set boot type to 'uefi'
28 Run an image using UEFI:
29 $ run_archiso -u -i archiso-2020.05.23-x86_64.iso
33 cleanup_working_dir() {
34 if [ -d "${working_dir}" ]; then
35 rm -rf "${working_dir}"
40 if [ ! -f /usr/share/edk2-ovmf/x64/OVMF_VARS.fd ]; then
41 echo "ERROR: OVMF_VARS.fd not found. Install edk2-ovmf."
44 cp -av /usr/share/edk2-ovmf/x64/OVMF_VARS.fd "${working_dir}"
48 if [ -z "$image" ]; then
49 echo "ERROR: Image name can not be empty."
52 if [ ! -f "$image" ]; then
53 echo "ERROR: Image file ($image) does not exist."
59 [ "$boot_type" = "bios" ] && run_image_using_bios
60 [ "$boot_type" = "uefi" ] && run_image_using_uefi
63 run_image_using_bios() {
65 -boot order=d,menu=on,reboot-timeout=5000 \
66 -m size=3072,slots=0,maxmem=$((3072*1024*1024)) \
68 -name archiso,process=archiso_0 \
69 -drive file="${image}",media=cdrom,readonly=on,if=virtio \
72 -device virtio-net-pci,netdev=net0 -netdev user,id=net0 \
77 run_image_using_uefi() {
78 local ovmf_code=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd
79 local secure_boot_state=off
81 if [ "${secure_boot}" == "yes" ]; then
82 echo "Using Secure Boot"
83 ovmf_code=/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd
87 -boot order=d,menu=on,reboot-timeout=5000 \
88 -m size=3072,slots=0,maxmem=$((3072*1024*1024)) \
90 -name archiso,process=archiso_0 \
91 -drive file="${image}",media=cdrom,readonly=on,if=virtio \
92 -drive if=pflash,format=raw,unit=0,file="${ovmf_code}",readonly \
93 -drive if=pflash,format=raw,unit=1,file="${working_dir}/OVMF_VARS.fd" \
94 -machine type=q35,smm=on,accel=kvm \
95 -global driver=cfi.pflash01,property=secure,value="${secure_boot_state}" \
96 -global ICH9-LPC.disable_s3=1 \
99 -device virtio-net-pci,netdev=net0 -netdev user,id=net0 \
105 if [ -z "$image" ]; then
106 echo "ERROR: Image name can not be empty."
109 if [ ! -f "$image" ]; then
110 echo "ERROR: Image ($image) does not exist."
119 working_dir="$(mktemp -d)"
120 trap cleanup_working_dir EXIT
122 if [ ${#@} -gt 0 ]; then
123 while getopts 'bhi:su' flag; do
142 echo "Error: Wrong option. Try 'run_archiso -h'."