Allow overriding some VM arguments via env vars (#519)

* allow overriding MACHINE_TYPE,MAC_DISK_DEV,NET_DEVICE,SMM via env vars

* allow overriding EFI_CODE,EFI_EXTRA_VARS
This commit is contained in:
3nprob 2022-08-18 08:45:10 +00:00 committed by GitHub
parent 1b1bd84e6a
commit 8e8c65eac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 67 deletions

124
quickemu
View File

@ -212,7 +212,7 @@ function vm_boot() {
local DISK_USED="" local DISK_USED=""
local DISPLAY_DEVICE="" local DISPLAY_DEVICE=""
local DISPLAY_RENDER="" local DISPLAY_RENDER=""
local EFI_CODE="" local EFI_CODE="${EFI_CODE}"
local EFI_VARS="" local EFI_VARS=""
local GUEST_CPU_CORES="" local GUEST_CPU_CORES=""
local GUEST_CPU_LOGICAL_CORES="" local GUEST_CPU_LOGICAL_CORES=""
@ -226,13 +226,13 @@ function vm_boot() {
local KERNEL_NODE="" local KERNEL_NODE=""
local KERNEL_VER="?" local KERNEL_VER="?"
local LSB_DESCRIPTION="Unknown OS" local LSB_DESCRIPTION="Unknown OS"
local MACHINE_TYPE="q35" local MACHINE_TYPE="${MACHINE_TYPE:-q35}"
local MAC_BOOTLOADER="" local MAC_BOOTLOADER=""
local MAC_MISSING="" local MAC_MISSING=""
local MAC_DISK_DEV="ide-hd,bus=ahci.2" local MAC_DISK_DEV="${MAC_DISK_DEV:-ide-hd,bus=ahci.2}"
local NET_DEVICE="virtio-net" local NET_DEVICE="${NET_DEVICE:-virtio-net}"
local OSK="" local OSK=""
local SMM="off" local SMM="${SMM:-off}"
local USB_HOST_PASSTHROUGH_CONTROLLER="qemu-xhci" local USB_HOST_PASSTHROUGH_CONTROLLER="qemu-xhci"
local VIDEO="" local VIDEO=""
@ -379,69 +379,59 @@ function vm_boot() {
# does not support SMM. # does not support SMM.
# https://bugzilla.redhat.com/show_bug.cgi?id=1929357#c5 # https://bugzilla.redhat.com/show_bug.cgi?id=1929357#c5
case ${secureboot} in if [ ! -z "${EFI_CODE}" ] || [ ! -e "${EFI_CODE}" ]; then
on) case ${secureboot} in
if [ -e "/usr/share/OVMF/OVMF_CODE_4M.secboot.fd" ]; then on)
EFI_CODE="/usr/share/OVMF/OVMF_CODE_4M.secboot.fd" ovmfs=("/usr/share/OVMF/OVMF_CODE_4M.secboot.fd","/usr/share/OVMF/OVMF_VARS_4M.fd" \
efi_vars "/usr/share/OVMF/OVMF_VARS_4M.fd" "${EFI_VARS}" "/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd","/usr/share/edk2/ovmf/OVMF_VARS.fd" \
elif [ -e "/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd" ]; then "/usr/share/OVMF/x64/OVMF_CODE.secboot.fd","/usr/share/OVMF/x64/OVMF_VARS.fd" \
EFI_CODE="/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd" "/usr/share/edk2-ovmf/OVMF_CODE.secboot.fd","/usr/share/edk2-ovmf/OVMF_VARS.fd" \
efi_vars "/usr/share/edk2/ovmf/OVMF_VARS.fd" "${EFI_VARS}" "/usr/share/qemu/ovmf-x86_64-smm-ms-code.bin","/usr/share/qemu/ovmf-x86_64-smm-ms-vars.bin" \
elif [ -e "/usr/share/OVMF/x64/OVMF_CODE.secboot.fd" ]; then "/usr/share/qemu/edk2-x86_64-secure-code.fd","/usr/share/qemu/edk2-x86_64-code.fd" \
EFI_CODE="/usr/share/OVMF/x64/OVMF_CODE.secboot.fd" "/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd","/usr/share/edk2-ovmf/x64/OVMF_VARS.fd"
efi_vars "/usr/share/OVMF/x64/OVMF_VARS.fd" "${EFI_VARS}" )
elif [ -e "/usr/share/edk2-ovmf/OVMF_CODE.secboot.fd" ]; then ;;
EFI_CODE="/usr/share/edk2-ovmf/OVMF_CODE.secboot.fd" *)
efi_vars "/usr/share/edk2-ovmf/OVMF_VARS.fd" "${EFI_VARS}" ovmfs=("/usr/share/OVMF/OVMF_CODE_4M.fd","/usr/share/OVMF/OVMF_VARS_4M.fd" \
elif [ -e "/usr/share/qemu/ovmf-x86_64-smm-ms-code.bin" ]; then "/usr/share/edk2/ovmf/OVMF_CODE.fd","/usr/share/edk2/ovmf/OVMF_VARS.fd" \
EFI_CODE="/usr/share/qemu/ovmf-x86_64-smm-ms-code.bin" "/usr/share/OVMF/OVMF_CODE.fd","/usr/share/OVMF/OVMF_VARS.fd" \
efi_vars "/usr/share/qemu/ovmf-x86_64-smm-ms-vars.bin" "${EFI_VARS}" "/usr/share/OVMF/x64/OVMF_CODE.fd","/usr/share/OVMF/x64/OVMF_VARS.fd" \
elif [ -e "/usr/share/qemu/edk2-x86_64-secure-code.fd" ]; then "/usr/share/edk2-ovmf/OVMF_CODE.fd","/usr/share/edk2-ovmf/OVMF_VARS.fd" \
EFI_CODE="/usr/share/qemu/edk2-x86_64-secure-code.fd" "/usr/share/qemu/ovmf-x86_64-4m-code.bin","/usr/share/qemu/ovmf-x86_64-4m-vars.bin" \
efi_vars "/usr/share/qemu/edk2-x86_64-code.fd" "${EFI_VARS}" "/usr/share/qemu/edk2-x86_64-code.fd","/usr/share/qemu/edk2-x86_64-code.fd" \
# Solus new place to hide "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd","/usr/share/edk2-ovmf/x64/OVMF_VARS.fd"
elif [ -e "/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd" ]; then )
EFI_CODE="/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd" ;;
efi_vars "/usr/share/edk2-ovmf/x64/OVMF_VARS.fd" "${EFI_VARS}" esac
else # Attempt each EFI_CODE file one by one, selecting the corresponding code and vars
echo "ERROR! SecureBoot was requested but no SecureBoot capable firmware was found." # when an existing file is found.
echo " Please install OVMF firmware." _IFS=$IFS
exit 1 IFS=","
for f in "${ovmfs[@]}"; do
set -- $f;
if [ -e "${1}" ]; then
EFI_CODE="${1}"
EFI_EXTRA_VARS="${2}"
fi fi
;; done
*) IFS=$_IFS
if [ -e "/usr/share/OVMF/OVMF_CODE_4M.fd" ]; then fi
EFI_CODE="/usr/share/OVMF/OVMF_CODE_4M.fd" if [ -z "${EFI_CODE}" ] || [ ! -e "${EFI_CODE}" ]; then
efi_vars "/usr/share/OVMF/OVMF_VARS_4M.fd" "${EFI_VARS}" if [ "$secureboot" == "on" ]; then
elif [ -e "/usr/share/edk2/ovmf/OVMF_CODE.fd" ]; then echo "ERROR! SecureBoot was requested but no SecureBoot capable firmware was found."
EFI_CODE="/usr/share/edk2/ovmf/OVMF_CODE.fd" else
efi_vars "/usr/share/edk2/ovmf/OVMF_VARS.fd" "${EFI_VARS}" echo "ERROR! EFI boot requested but no EFI firmware found."
elif [ -e "/usr/share/OVMF/OVMF_CODE.fd" ]; then fi
EFI_CODE="/usr/share/OVMF/OVMF_CODE.fd" echo " Please install OVMF firmware."
efi_vars "/usr/share/OVMF/OVMF_VARS.fd" "${EFI_VARS}" exit 1
elif [ -e "/usr/share/OVMF/x64/OVMF_CODE.fd" ]; then fi
EFI_CODE="/usr/share/OVMF/x64/OVMF_CODE.fd" if [ ! -z "${EFI_EXTRA_VARS}" ]; then
efi_vars "/usr/share/OVMF/x64/OVMF_VARS.fd" "${EFI_VARS}" if [ ! -e "${EFI_EXTRA_VARS}" ]; then
elif [ -e "/usr/share/edk2-ovmf/OVMF_CODE.fd" ]; then echo " - EFI: ERROR! EFI_EXTRA_VARS file ${EFI_EXTRA_VARS} does not exist."
EFI_CODE="/usr/share/edk2-ovmf/OVMF_CODE.fd" exit 1
efi_vars "/usr/share/edk2-ovmf/OVMF_VARS.fd" "${EFI_VARS}" fi
elif [ -e "/usr/share/qemu/ovmf-x86_64-4m-code.bin" ]; then efi_vars "${EFI_EXTRA_VARS}" "${EFI_VARS}"
EFI_CODE="/usr/share/qemu/ovmf-x86_64-4m-code.bin" fi
efi_vars "/usr/share/qemu/ovmf-x86_64-4m-vars.bin" "${EFI_VARS}"
elif [ -e "/usr/share/qemu/edk2-x86_64-code.fd" ]; then
EFI_CODE="/usr/share/qemu/edk2-x86_64-code.fd"
efi_vars "/usr/share/qemu/edk2-x86_64-code.fd" "${EFI_VARS}"
# Solus
elif [ -e "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" ]; then
EFI_CODE="/usr/share/edk2-ovmf/x64/OVMF_CODE.fd"
efi_vars "/usr/share/edk2-ovmf/x64/OVMF_VARS.fd" "${EFI_VARS}"
else
echo "ERROR! EFI boot requested but no EFI firmware found."
echo " Please install OVMF firmware."
exit 1
fi
;;
esac
# Make sure EFI_VARS references an actual, writeable, file # Make sure EFI_VARS references an actual, writeable, file
if [ ! -f "${EFI_VARS}" ] || [ ! -w "${EFI_VARS}" ]; then if [ ! -f "${EFI_VARS}" ] || [ ! -w "${EFI_VARS}" ]; then