From db5b6a3c58e9a49e3b45a6359b819aed7c24f76e Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 7 Jan 2024 20:36:49 +0100 Subject: [PATCH] feat: Download VirtIO drivers (#304) --- src/disk.sh | 17 ++++++++++++++--- src/install.sh | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 9aafa59..800d115 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -5,21 +5,32 @@ set -Eeuo pipefail : ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' : ${DISK_FMT:=''} # Disk file format, can be set to "raw" or "qcow2" (default) +: ${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. : ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD -: ${DISK_FLAGS:=''} # Specifies the options for use with the qcow2 disk format -BOOT="$STORAGE/boot.img" +BOOT="$STORAGE/$BASE" +DRIVERS="$STORAGE/drivers.img" DISK_OPTS="-object iothread,id=io2" +if [ -f "$BOOT" ] || [ -f "$DRIVERS" ]; then + DISK_OPTS="$DISK_OPTS \ + -device virtio-scsi-pci,id=scsi0,iothread=io2,addr=0x5" +fi + if [ -f "$BOOT" ]; then DISK_OPTS="$DISK_OPTS \ - -device virtio-scsi-pci,id=scsi0,iothread=io2,addr=0x5 \ -drive id=cdrom0,if=none,format=raw,readonly=on,file=$BOOT \ -device scsi-cd,bus=scsi0.0,drive=cdrom0,bootindex=10" fi +if [ -f "$DRIVERS" ]; then + DISK_OPTS="$DISK_OPTS \ + -drive id=cdrom1,if=none,format=raw,readonly=on,file=$DRIVERS \ + -device scsi-cd,bus=scsi0.1,drive=cdrom1" +fi + fmt2ext() { local DISK_FMT=$1 diff --git a/src/install.sh b/src/install.sh index e7eeec8..bb2ff90 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1,13 +1,15 @@ #!/usr/bin/env bash set -Eeuo pipefail -FILE="$STORAGE/boot.img" -[ -f "$FILE" ] && return 0 +BASE="boot.img" +[ -f "$STORAGE/$BASE" ] && return 0 -TMP="/boot.img" -rm -f "$TMP" +if [ -z "$BOOT" ]; then + error "No boot disk specified, set BOOT= to the URL of an ISO file." && exit 64 +fi -info "Downloading $BOOT as boot image..." +BASE=$(basename "$BOOT") +[ -f "$STORAGE/$BASE" ] && return 0 # Check if running with interactive TTY or redirected to docker log if [ -t 1 ]; then @@ -16,7 +18,26 @@ else PROGRESS="--progress=dot:giga" fi -[[ "$DEBUG" == [Yy1]* ]] && set -x +if [[ "${BOOT_MODE,,}" == "windows" ]]; then + + DEST="$STORAGE/drivers.img" + + if [ ! -f "$DEST" ]; then + + info "Downloading VirtIO drivers for Windows..." + DRIVERS="https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" + + { wget "$DRIVERS" -O "$DEST" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || : + + (( rc != 0 )) && info "Failed to download $DRIVERS, reason: $rc" && rm -f "$DEST" + + fi +fi + +TMP="$STORAGE/${BASE%.*}.tmp" +rm -f "$TMP" + +info "Downloading $BASE as boot image..." { wget "$BOOT" -O "$TMP" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || : @@ -29,9 +50,6 @@ if ((SIZE<100000)); then error "Invalid ISO file: Size is smaller than 100 KB" && exit 62 fi -mv -f "$TMP" "$FILE" - -{ set +x; } 2>/dev/null -[[ "$DEBUG" == [Yy1]* ]] && echo +mv -f "$TMP" "$STORAGE/$BASE" return 0