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 \
70 -device virtio-net-pci,netdev=net0 -netdev user,id=net0 \
75 run_image_using_uefi() {
76 local ovmf_code=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd
77 local secure_boot_state=off
79 if [ "${secure_boot}" == "yes" ]; then
80 echo "Using Secure Boot"
81 ovmf_code=/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd
85 -boot order=d,menu=on,reboot-timeout=5000 \
86 -m size=3072,slots=0,maxmem=$((3072*1024*1024)) \
88 -name archiso,process=archiso_0 \
89 -drive file="${image}",media=cdrom,readonly=on,if=virtio \
90 -drive if=pflash,format=raw,unit=0,file="${ovmf_code}",readonly \
91 -drive if=pflash,format=raw,unit=1,file="${working_dir}/OVMF_VARS.fd" \
92 -machine type=q35,smm=on,accel=kvm \
93 -global driver=cfi.pflash01,property=secure,value="${secure_boot_state}" \
94 -global ICH9-LPC.disable_s3=1 \
95 -device virtio-net-pci,netdev=net0 -netdev user,id=net0 \
101 if [ -z "$image" ]; then
102 echo "ERROR: Image name can not be empty."
105 if [ ! -f "$image" ]; then
106 echo "ERROR: Image ($image) does not exist."
115 working_dir="$(mktemp -d)"
116 trap cleanup_working_dir EXIT
118 if [ ${#@} -gt 0 ]; then
119 while getopts 'bhi:su' flag; do
138 echo "Error: Wrong option. Try 'run_archiso -h'."