Skip to content

Commit

Permalink
feat: Default to UEFI for external images (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Jun 14, 2024
1 parent 6abc58e commit fd24f92
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN set -eu && \
wget \
7zip \
ovmf \
fdisk \
nginx \
swtpm \
procps \
Expand Down
23 changes: 11 additions & 12 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
set -Eeuo pipefail

# Docker environment variables
: "${BIOS:=""}" # BIOS file
: "${TPM:="N"}" # Disable TPM
: "${SMM:="N"}" # Disable SMM
: "${BIOS:=""}" # BIOS file
: "${BOOT_MODE:="legacy"}" # Boot mode

BOOT_DESC=""
BOOT_OPTS=""
Expand All @@ -14,24 +13,24 @@ SECURE="off"
[[ "$SMM" == [Yy1]* ]] && SECURE="on"

if [ -n "$BIOS" ]; then
BOOT_MODE="custom"
BOOT_OPTS="-bios $BIOS"
BOOT_DESC=" with custom BIOS file"
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"
;;
esac
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"
fi

case "${BOOT_MODE,,}" in
"legacy" )
BOOT_OPTS=""
BOOT_DESC=" with SeaBIOS"
;;
"uefi" )
BOOT_DESC=" with OVMF"
"uefi" | "" )
BOOT_MODE="uefi"
ROM="OVMF_CODE_4M.fd"
VARS="OVMF_VARS_4M.fd"
;;
Expand Down
41 changes: 11 additions & 30 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,23 @@ detectType() {

case "${file,,}" in
*".iso" | *".img" | *".raw" | *".qcow2" )
BOOT="$file"
[ -n "${BOOT_MODE:-}" ] && return 0 ;;
BOOT="$file" ;;
* ) return 1 ;;
esac

# Automaticly detect UEFI-compatible images

case "${file,,}" in
*".iso" )

dir=$(isoinfo -f -i "$file")
if [ -z "$dir" ]; then
BOOT=""
error "Failed to read ISO file, invalid format!" && return 1
fi

dir=$(echo "${dir^^}" | grep "^/EFI")
[ -n "$dir" ] && BOOT_MODE="uefi" ;;

*".img" | *".raw" )
[ -n "$BOOT_MODE" ] && return 0
[[ "${file,,}" != *".iso" ]] && return 0

dir=$(sfdisk -l "$file")
if [ -z "$dir" ]; then
BOOT=""
error "Failed to read disk image file, invalid format!" && return 1
fi

dir=$(echo "${dir^^}" | grep "EFI SYSTEM")
[ -n "$dir" ] && BOOT_MODE="uefi" ;;

*".qcow2" )
# Automaticly detect UEFI-compatible ISO's
dir=$(isoinfo -f -i "$file")

# TODO: Detect boot mode from partition table in image
BOOT_MODE="uefi" ;;
if [ -z "$dir" ]; then
BOOT=""
error "Failed to read ISO file, invalid format!" && return 1
fi

esac
dir=$(echo "${dir^^}" | grep "^/EFI")
[ -z "$dir" ] && BOOT_MODE="legacy"

return 0
}
Expand Down
1 change: 1 addition & 0 deletions src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ echo "❯ For support visit $SUPPORT"
: "${RAM_SIZE:="1G"}" # Maximum RAM amount
: "${RAM_CHECK:="Y"}" # Check available RAM
: "${DISK_SIZE:="16G"}" # Initial data disk size
: "${BOOT_MODE:=""}" # Boot system with UEFI
: "${BOOT_INDEX:="9"}" # Boot index of CD drive

# Helper variables
Expand Down

0 comments on commit fd24f92

Please sign in to comment.