Skip to content

Commit

Permalink
feat: Support custom BIOS files (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Jun 12, 2024
1 parent 6425c68 commit 5dfcfcc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 48 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Docker container for running virtual machines using QEMU.

- Reduces the learning curve and eliminates the need for a dedicated Proxmox or ESXi server

- Has a web-based viewer to control the machine directly from your browser
- Web-based viewer to control the machine directly from your browser

- Uses high-performance QEMU options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed
- High-performance QEMU options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed

## Usage 🐳

Expand Down
64 changes: 36 additions & 28 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ set -Eeuo pipefail
# Docker environment variables
: "${TPM:="N"}" # Disable TPM
: "${SMM:="N"}" # Disable SMM
: "${BIOS:=""}" # BIOS file
: "${BOOT_MODE:="legacy"}" # Boot mode

BOOT_DESC=""
BOOT_OPTS=""

if [[ "${BOOT_MODE,,}" == "windows"* ]]; then

BOOT_OPTS="-rtc base=localtime"
BOOT_OPTS+=" -global ICH9-LPC.disable_s3=1"
BOOT_OPTS+=" -global ICH9-LPC.disable_s4=1"
SECURE="off"
[[ "$SMM" == [Yy1]* ]] && SECURE="on"

if [ -n "$BIOS" ]; then
BOOT_OPTS="-bios $BIOS"
return 0
fi

SECURE="off"
[[ "$SMM" == [Yy1]* ]] && SECURE="on"
case "${BOOT_MODE,,}" in
"windows"* )
BOOT_OPTS="-rtc base=localtime"
BOOT_OPTS+=" -global ICH9-LPC.disable_s3=1"
BOOT_OPTS+=" -global ICH9-LPC.disable_s4=1"
;;
esac

case "${BOOT_MODE,,}" in
"legacy" )
BOOT_OPTS=""
;;
"uefi" )
BOOT_DESC=" with UEFI"
BOOT_DESC=" with OVMF"
ROM="OVMF_CODE_4M.fd"
VARS="OVMF_VARS_4M.fd"
;;
Expand All @@ -47,38 +56,37 @@ case "${BOOT_MODE,,}" in
BOOT_DESC=" (legacy)"
USB="usb-ehci,id=ehci"
;;
"legacy" )
BOOT_OPTS=""
;;
*)
error "Unknown BOOT_MODE, value \"${BOOT_MODE}\" is not recognized!"
exit 33
;;
esac

if [[ "${BOOT_MODE,,}" != *"legacy" ]]; then
case "${BOOT_MODE,,}" in
"uefi" | "secure" | "windows" | "windows_plain" | "windows_secure" )

OVMF="/usr/share/OVMF"
DEST="$STORAGE/${BOOT_MODE,,}"
OVMF="/usr/share/OVMF"
DEST="$STORAGE/${BOOT_MODE,,}"

if [ ! -s "$DEST.rom" ] || [ ! -f "$DEST.rom" ]; then
[ ! -s "$OVMF/$ROM" ] || [ ! -f "$OVMF/$ROM" ] && error "UEFI boot file ($OVMF/$ROM) not found!" && exit 44
cp "$OVMF/$ROM" "$DEST.rom"
fi
if [ ! -s "$DEST.rom" ] || [ ! -f "$DEST.rom" ]; then
[ ! -s "$OVMF/$ROM" ] || [ ! -f "$OVMF/$ROM" ] && error "UEFI boot file ($OVMF/$ROM) not found!" && exit 44
cp "$OVMF/$ROM" "$DEST.rom"
fi

if [ ! -s "$DEST.vars" ] || [ ! -f "$DEST.vars" ]; then
[ ! -s "$OVMF/$VARS" ] || [ ! -f "$OVMF/$VARS" ]&& error "UEFI vars file ($OVMF/$VARS) not found!" && exit 45
cp "$OVMF/$VARS" "$DEST.vars"
fi
if [ ! -s "$DEST.vars" ] || [ ! -f "$DEST.vars" ]; then
[ ! -s "$OVMF/$VARS" ] || [ ! -f "$OVMF/$VARS" ]&& error "UEFI vars file ($OVMF/$VARS) not found!" && exit 45
cp "$OVMF/$VARS" "$DEST.vars"
fi

if [[ "${BOOT_MODE,,}" == "secure" ]] || [[ "${BOOT_MODE,,}" == "windows_secure" ]]; then
BOOT_OPTS+=" -global driver=cfi.pflash01,property=secure,value=on"
fi
if [[ "${BOOT_MODE,,}" == "secure" ]] || [[ "${BOOT_MODE,,}" == "windows_secure" ]]; then
BOOT_OPTS+=" -global driver=cfi.pflash01,property=secure,value=on"
fi

BOOT_OPTS+=" -drive file=$DEST.rom,if=pflash,unit=0,format=raw,readonly=on"
BOOT_OPTS+=" -drive file=$DEST.vars,if=pflash,unit=1,format=raw"
BOOT_OPTS+=" -drive file=$DEST.rom,if=pflash,unit=0,format=raw,readonly=on"
BOOT_OPTS+=" -drive file=$DEST.vars,if=pflash,unit=1,format=raw"

fi
;;
esac

if [[ "$TPM" == [Yy1]* ]]; then

Expand Down
28 changes: 15 additions & 13 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,21 @@ case "${DISK_TYPE,,}" in
* ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
esac

case "${MACHINE,,}" in
"virt" )
FALLBACK="usb" ;;
"pc-q35-2"* | "pc-i440fx-2"* )
FALLBACK="auto" ;;
* )
FALLBACK="ide" ;;
esac

if [ -z "${MEDIA_TYPE:-}" ]; then
case "${MACHINE,,}" in
"virt" | "pc-q35-2"* | "pc-i440fx-2"* )
MEDIA_TYPE="auto" ;;
* )
[[ "${DISK_TYPE,,}" != "blk" ]] && MEDIA_TYPE="$DISK_TYPE" || MEDIA_TYPE="ide" ;;
esac
if [[ "${DISK_TYPE,,}" == "blk" ]]; then
MEDIA_TYPE="$FALLBACK"
else
MEDIA_TYPE="$DISK_TYPE"
fi
fi

case "${MEDIA_TYPE,,}" in
Expand All @@ -553,13 +561,7 @@ DRIVERS="/drivers.iso"
[ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="$STORAGE/drivers.iso"

if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then
case "${MACHINE,,}" in
"virt" | "pc-q35-2"* | "pc-i440fx-2"* )
DRIVER_TYPE="auto" ;;
* )
DRIVER_TYPE="ide" ;;
esac
DISK_OPTS+=$(addMedia "$DRIVERS" "$DRIVER_TYPE" "1" "" "0x6")
DISK_OPTS+=$(addMedia "$DRIVERS" "$FALLBACK" "1" "" "0x6")
fi

DISK1_FILE="$STORAGE/data"
Expand Down
10 changes: 5 additions & 5 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ detect () {
[ ! -f "$file" ] && return 1
[ ! -s "$file" ] && return 1

dir=$(isoinfo -f -i "$file")

# Automaticly detect UEFI-compatible ISO's
if echo "${dir^^}" | grep -q "^/EFI"; then
[ -z "${BOOT_MODE:-}" ] && BOOT_MODE="uefi"
if [ -z "${BOOT_MODE:-}" ]; then
# Automaticly detect UEFI-compatible ISO's
dir=$(isoinfo -f -i "$file")
dir=$(echo "${dir^^}" | grep "^/EFI")
[ -n "$dir" ] && BOOT_MODE="uefi"
fi

BOOT="$file"
Expand Down

0 comments on commit 5dfcfcc

Please sign in to comment.