feat: Download VirtIO drivers (#304)

This commit is contained in:
Kroese 2024-01-07 20:36:49 +01:00 committed by GitHub
parent 2c47494721
commit db5b6a3c58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 13 deletions

View file

@ -5,21 +5,32 @@ set -Eeuo pipefail
: ${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_turing'
: ${DISK_FMT:=''} # Disk file format, can be set to "raw" or "qcow2" (default) : ${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_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_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_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" 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 if [ -f "$BOOT" ]; then
DISK_OPTS="$DISK_OPTS \ 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 \ -drive id=cdrom0,if=none,format=raw,readonly=on,file=$BOOT \
-device scsi-cd,bus=scsi0.0,drive=cdrom0,bootindex=10" -device scsi-cd,bus=scsi0.0,drive=cdrom0,bootindex=10"
fi 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() { fmt2ext() {
local DISK_FMT=$1 local DISK_FMT=$1

View file

@ -1,13 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail set -Eeuo pipefail
FILE="$STORAGE/boot.img" BASE="boot.img"
[ -f "$FILE" ] && return 0 [ -f "$STORAGE/$BASE" ] && return 0
TMP="/boot.img" if [ -z "$BOOT" ]; then
rm -f "$TMP" 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 # Check if running with interactive TTY or redirected to docker log
if [ -t 1 ]; then if [ -t 1 ]; then
@ -16,7 +18,26 @@ else
PROGRESS="--progress=dot:giga" PROGRESS="--progress=dot:giga"
fi 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=$?; } || : { 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 error "Invalid ISO file: Size is smaller than 100 KB" && exit 62
fi fi
mv -f "$TMP" "$FILE" mv -f "$TMP" "$STORAGE/$BASE"
{ set +x; } 2>/dev/null
[[ "$DEBUG" == [Yy1]* ]] && echo
return 0 return 0