Unverified Commit db5b6a3c authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Download VirtIO drivers (#304)

parent 2c474947
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -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

+28 −10
Original line number Diff line number Diff line
#!/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