Skip to content

Commit

Permalink
fix: Disable Hyper-V in Windows Legacy mode (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Oct 8, 2024
1 parent 074058a commit 5e4aec3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -Eeuo pipefail

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

Expand Down Expand Up @@ -52,6 +52,7 @@ case "${BOOT_MODE,,}" in
VARS="OVMF_VARS_4M.ms.fd"
;;
"windows_legacy" )
HV="N"
SECURE="on"
BOOT_DESC=" (legacy)"
USB="usb-ehci,id=ehci"
Expand Down Expand Up @@ -114,8 +115,8 @@ if [[ "$TPM" == [Yy1]* ]]; then
BOOT_OPTS+=" -chardev socket,id=chrtpm,path=/run/swtpm-sock"
BOOT_OPTS+=" -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0"
fi
fi

fi
fi

return 0
56 changes: 39 additions & 17 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ set -Eeuo pipefail

# Docker environment variables

: "${DISK_IO:="native"}" # I/O Mode, can be set to 'native', 'threads' or 'io_turing'
: "${DISK_IO:="native"}" # I/O Mode, can be set to 'native', 'threads' or 'io_uring'
: "${DISK_FMT:=""}" # Disk file format, can be set to "raw" (default) or "qcow2"
: "${DISK_TYPE:=""}" # Device type to be used, choose "ide", "usb", "blk" or "scsi"
: "${DISK_TYPE:=""}" # Device type to be used, "sata", "nvme", "blk" or "scsi"
: "${DISK_FLAGS:=""}" # Specifies the options for use with the qcow2 disk format
: "${DISK_CACHE:="none"}" # Caching mode, can be set to 'writeback' for better performance
: "${DISK_DISCARD:="on"}" # Controls whether unmap (TRIM) commands are passed to the host.
Expand Down Expand Up @@ -363,6 +363,7 @@ createDevice () {
local result=" -drive file=$DISK_FILE,id=$DISK_ID,format=$DISK_FMT,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on"

case "${DISK_TYPE,,}" in
"none" ) ;;
"auto" )
echo "$result"
;;
Expand All @@ -371,7 +372,12 @@ createDevice () {
-device usb-storage,drive=${DISK_ID}${index}"
echo "$result"
;;
"ide" )
"nvme" )
result+=",if=none \
-device nvme,drive=${DISK_ID}${index},serial=deadbeaf${DISK_INDEX}"
echo "$result"
;;
"ide" | "sata" )
result+=",if=none \
-device ich9-ahci,id=ahci${DISK_INDEX},addr=$DISK_ADDRESS \
-device ide-hd,drive=${DISK_ID},bus=ahci$DISK_INDEX.0,rotation_rate=$DISK_ROTATION${index}"
Expand Down Expand Up @@ -406,6 +412,7 @@ addMedia () {
local result=" -drive file=$DISK_FILE,id=$DISK_ID,format=raw,cache=unsafe,readonly=on,media=cdrom"

case "${DISK_TYPE,,}" in
"none" ) ;;
"auto" )
echo "$result"
;;
Expand All @@ -414,7 +421,12 @@ addMedia () {
-device usb-storage,drive=${DISK_ID}${index},removable=on"
echo "$result"
;;
"ide" )
"nvme" )
result+=",if=none \
-device nvme,drive=${DISK_ID}${index},serial=deadbeaf${DISK_INDEX}"
echo "$result"
;;
"ide" | "sata" )
result+=",if=none \
-device ich9-ahci,id=ahci${DISK_INDEX},addr=$DISK_ADDRESS \
-device ide-cd,drive=${DISK_ID},bus=ahci${DISK_INDEX}.0${index}"
Expand Down Expand Up @@ -461,7 +473,7 @@ addDisk () {
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")

if (( DATA_SIZE < 1 )); then
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
error "Invalid value for ${DISK_DESC^^}_SIZE: $DISK_SPACE" && exit 73
fi

if (( DATA_SIZE < 104857600 )); then
Expand Down Expand Up @@ -532,23 +544,33 @@ html "Initializing disks..."
[ -z "${DISK_NAME:-}" ] && DISK_NAME="data"

case "${DISK_TYPE,,}" in
"ide" | "usb" | "scsi" | "blk" | "auto" ) ;;
"ide" | "sata" | "nvme" | "usb" | "scsi" | "blk" | "auto" | "none" ) ;;
* ) error "Invalid DISK_TYPE specified, value \"$DISK_TYPE\" is not recognized!" && 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" )
MEDIA_TYPE="usb" ;;
"pc-q35-2"* | "pc-i440fx-2"* )
MEDIA_TYPE="auto" ;;
* )
MEDIA_TYPE="ide" ;;
esac
if [[ "${BOOT_MODE:-}" != "windows"* ]]; then
if [[ "${DISK_TYPE,,}" == "blk" ]]; then
MEDIA_TYPE="$FALLBACK"
else
MEDIA_TYPE="$DISK_TYPE"
fi
else
MEDIA_TYPE="$FALLBACK"
fi
fi

case "${MEDIA_TYPE,,}" in
"ide" | "usb" | "scsi" | "blk" | "auto" ) ;;
"ide" | "sata" | "nvme" | "usb" | "scsi" | "blk" | "auto" | "none" ) ;;
* ) error "Invalid MEDIA_TYPE specified, value \"$MEDIA_TYPE\" is not recognized!" && exit 80 ;;
esac

Expand All @@ -569,14 +591,14 @@ DRIVERS="/drivers.iso"
[ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="$STORAGE/drivers.iso"

if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then
DISK_OPTS+=$(addMedia "$DRIVERS" "$MEDIA_TYPE" "" "0x6")
DISK_OPTS+=$(addMedia "$DRIVERS" "$FALLBACK" "" "0x6")
fi

RESCUE="/start.iso"
[ ! -f "$RESCUE" ] || [ ! -s "$RESCUE" ] && RESCUE="$STORAGE/start.iso"

if [ -f "$RESCUE" ] && [ -s "$RESCUE" ]; then
DISK_OPTS+=$(addMedia "$RESCUE" "$MEDIA_TYPE" "1" "0x6")
DISK_OPTS+=$(addMedia "$RESCUE" "$FALLBACK" "1" "0x6")
fi

DISK1_FILE="$STORAGE/${DISK_NAME}"
Expand Down

0 comments on commit 5e4aec3

Please sign in to comment.