feat: Detect EFI-compatible images (#117)

This commit is contained in:
Kroese 2024-06-12 04:42:40 +02:00 committed by GitHub
parent c2a7932d8e
commit bdd0f1a1a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 67 additions and 47 deletions

View file

@ -21,6 +21,7 @@ RUN set -eu && \
dnsmasq \ dnsmasq \
net-tools \ net-tools \
qemu-utils \ qemu-utils \
genisoimage \
ca-certificates \ ca-certificates \
netcat-openbsd \ netcat-openbsd \
qemu-system-arm \ qemu-system-arm \

View file

@ -22,9 +22,9 @@ Docker container for running ARM-based virtual machines using QEMU, for devices
- Reduces the learning curve and eliminates the need for a dedicated Proxmox or ESXi server - 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
*Note: for KVM acceleration you need a Linux-based operating system, as it's not available on MacOS unfortunately.* *Note: for KVM acceleration you need a Linux-based operating system, as it's not available on MacOS unfortunately.*

View file

@ -2,15 +2,24 @@
set -Eeuo pipefail set -Eeuo pipefail
# Docker environment variables # Docker environment variables
: "${BIOS:=""}" # Bios file : "${BIOS:=""}" # BIOS file
: "${BOOT_MODE:="legacy"}" # Boot mode
SECURE="off" SECURE="off"
BOOT_OPTS="" BOOT_OPTS=""
BOOT_DESC="" BOOT_DESC=""
DIR="/usr/share/qemu"
if [ -n "$BIOS" ]; then
BOOT_OPTS="-bios $BIOS"
return 0
fi
case "${BOOT_MODE,,}" in case "${BOOT_MODE,,}" in
"legacy" )
BOOT_OPTS=""
;;
"uefi" ) "uefi" )
BOOT_DESC=" with OVMF"
ROM="AAVMF_CODE.no-secboot.fd" ROM="AAVMF_CODE.no-secboot.fd"
VARS="AAVMF_VARS.fd" VARS="AAVMF_VARS.fd"
;; ;;
@ -38,12 +47,8 @@ case "${BOOT_MODE,,}" in
;; ;;
esac esac
if [ -n "$BIOS" ]; then case "${BOOT_MODE,,}" in
"uefi" | "secure" | "windows" | "windows_secure" )
BOOT_OPTS+=" -bios $DIR/$BIOS"
return 0
fi
AAVMF="/usr/share/AAVMF/" AAVMF="/usr/share/AAVMF/"
DEST="$STORAGE/${BOOT_MODE,,}" DEST="$STORAGE/${BOOT_MODE,,}"
@ -65,4 +70,7 @@ fi
BOOT_OPTS+=" -drive file=$DEST.rom,if=pflash,unit=0,format=raw,readonly=on" 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.vars,if=pflash,unit=1,format=raw"
;;
esac
return 0 return 0

View file

@ -531,13 +531,21 @@ case "${DISK_TYPE,,}" in
* ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;; * ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
esac esac
if [ -z "${MEDIA_TYPE:-}" ]; then
case "${MACHINE,,}" in case "${MACHINE,,}" in
"virt" | "pc-q35-2"* | "pc-i440fx-2"* ) "virt" )
MEDIA_TYPE="auto" ;; FALLBACK="usb" ;;
"pc-q35-2"* | "pc-i440fx-2"* )
FALLBACK="auto" ;;
* ) * )
[[ "${DISK_TYPE,,}" != "blk" ]] && MEDIA_TYPE="$DISK_TYPE" || MEDIA_TYPE="ide" ;; FALLBACK="ide" ;;
esac esac
if [ -z "${MEDIA_TYPE:-}" ]; then
if [[ "${DISK_TYPE,,}" == "blk" ]]; then
MEDIA_TYPE="$FALLBACK"
else
MEDIA_TYPE="$DISK_TYPE"
fi
fi fi
case "${MEDIA_TYPE,,}" in case "${MEDIA_TYPE,,}" in
@ -553,13 +561,7 @@ DRIVERS="/drivers.iso"
[ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="$STORAGE/drivers.iso" [ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="$STORAGE/drivers.iso"
if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then
case "${MACHINE,,}" in DISK_OPTS+=$(addMedia "$DRIVERS" "$FALLBACK" "1" "" "0x6")
"virt" | "pc-q35-2"* | "pc-i440fx-2"* )
DRIVER_TYPE="auto" ;;
* )
DRIVER_TYPE="ide" ;;
esac
DISK_OPTS+=$(addMedia "$DRIVERS" "$DRIVER_TYPE" "1" "" "0x6")
fi fi
DISK1_FILE="$STORAGE/data" DISK1_FILE="$STORAGE/data"

View file

@ -6,10 +6,10 @@ set -Eeuo pipefail
: "${VGA:=""}" # VGA adaptor : "${VGA:=""}" # VGA adaptor
: "${DISPLAY:="web"}" # Display type : "${DISPLAY:="web"}" # Display type
if [[ "${BOOT_MODE,,}" != "windows" ]]; then if [[ "${BOOT_MODE:-}" == "windows"* ]]; then
[ -z "$VGA" ] && VGA="virtio-gpu"
else
[ -z "$VGA" ] && VGA="ramfb" [ -z "$VGA" ] && VGA="ramfb"
else
[ -z "$VGA" ] && VGA="virtio-gpu"
fi fi
case "${DISPLAY,,}" in case "${DISPLAY,,}" in

View file

@ -1,18 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail set -Eeuo pipefail
iso () { detect () {
local dir=""
local file="$1" local file="$1"
[ ! -f "$file" ] && return 1 [ ! -f "$file" ] && return 1
[ ! -s "$file" ] && return 1 [ ! -s "$file" ] && return 1
dir=$(isoinfo -f -i "$file")
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" BOOT="$file"
return 0 return 0
} }
file=$(find / -maxdepth 1 -type f -iname boot.iso | head -n 1) file=$(find / -maxdepth 1 -type f -iname boot.iso | head -n 1)
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso | head -n 1) [ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso | head -n 1)
iso "$file" && return 0 detect "$file" && return 0
if [ -z "$BOOT" ] || [[ "$BOOT" == *"example.com/image.iso" ]]; then if [ -z "$BOOT" ] || [[ "$BOOT" == *"example.com/image.iso" ]]; then
hasDisk && return 0 hasDisk && return 0
@ -20,12 +30,12 @@ if [ -z "$BOOT" ] || [[ "$BOOT" == *"example.com/image.iso" ]]; then
fi fi
base=$(basename "$BOOT") base=$(basename "$BOOT")
iso "$STORAGE/$base" && return 0 detect "$STORAGE/$base" && return 0
base=$(basename "${BOOT%%\?*}") base=$(basename "${BOOT%%\?*}")
: "${base//+/ }"; printf -v base '%b' "${_//%/\\x}" : "${base//+/ }"; printf -v base '%b' "${_//%/\\x}"
base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g') base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g')
iso "$STORAGE/$base" && return 0 detect "$STORAGE/$base" && return 0
TMP="$STORAGE/${base%.*}.tmp" TMP="$STORAGE/${base%.*}.tmp"
rm -f "$TMP" rm -f "$TMP"
@ -61,6 +71,6 @@ if ((size<100000)); then
fi fi
mv -f "$TMP" "$STORAGE/$base" mv -f "$TMP" "$STORAGE/$base"
! iso "$STORAGE/$base" && exit 63 ! detect "$STORAGE/$base" && exit 63
return 0 return 0

View file

@ -25,7 +25,6 @@ echo " For support visit $SUPPORT"
: "${RAM_CHECK:="Y"}" # Check available RAM : "${RAM_CHECK:="Y"}" # Check available RAM
: "${DISK_SIZE:="16G"}" # Initial data disk size : "${DISK_SIZE:="16G"}" # Initial data disk size
: "${BOOT_INDEX:="10"}" # Boot index of CD drive : "${BOOT_INDEX:="10"}" # Boot index of CD drive
: "${BOOT_MODE:="uefi"}" # Boot in UEFI mode
# Helper variables # Helper variables