Unverified Commit 5dfcfcc3 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Support custom BIOS files (#559)

parent 6425c68a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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  🐳

+36 −28
Original line number Diff line number Diff line
@@ -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
SECURE="off"
[[ "$SMM" == [Yy1]* ]] && SECURE="on"

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

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"

fi

SECURE="off"
[[ "$SMM" == [Yy1]* ]] && SECURE="on"
    ;;
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"
    ;;
@@ -47,16 +56,14 @@ 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,,}"
@@ -78,7 +85,8 @@ if [[ "${BOOT_MODE,,}" != *"legacy" ]]; then
    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

+15 −13
Original line number Diff line number Diff line
@@ -531,13 +531,21 @@ case "${DISK_TYPE,,}" in
  * ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
esac

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

if [ -z "${MEDIA_TYPE:-}" ]; then
  if [[ "${DISK_TYPE,,}" == "blk" ]]; then
    MEDIA_TYPE="$FALLBACK"
  else
    MEDIA_TYPE="$DISK_TYPE"
  fi
fi

case "${MEDIA_TYPE,,}" in
@@ -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"
+5 −5
Original line number Diff line number Diff line
@@ -7,11 +7,11 @@ detect () {
  [ ! -f "$file" ] && return 1
  [ ! -s "$file" ] && return 1

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

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

  BOOT="$file"