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

feat: Always use IDE for CD-ROM devices (#544)

parent 1ceaedd1
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -12,8 +12,8 @@ BOOT_OPTS=""
if [[ "${BOOT_MODE,,}" == "windows"* ]]; then

  BOOT_OPTS="-rtc base=localtime"
  BOOT_OPTS="$BOOT_OPTS -global ICH9-LPC.disable_s3=1"
  BOOT_OPTS="$BOOT_OPTS -global ICH9-LPC.disable_s4=1"
  BOOT_OPTS+=" -global ICH9-LPC.disable_s3=1"
  BOOT_OPTS+=" -global ICH9-LPC.disable_s4=1"

fi

@@ -72,11 +72,11 @@ if [[ "${BOOT_MODE,,}" != *"legacy" ]]; then
  fi

  if [[ "${BOOT_MODE,,}" == "secure" ]] || [[ "${BOOT_MODE,,}" == "windows_secure" ]]; then
    BOOT_OPTS="$BOOT_OPTS -global driver=cfi.pflash01,property=secure,value=on"
    BOOT_OPTS+=" -global driver=cfi.pflash01,property=secure,value=on"
  fi

  BOOT_OPTS="$BOOT_OPTS -drive file=$DEST.rom,if=pflash,unit=0,format=raw,readonly=on"
  BOOT_OPTS="$BOOT_OPTS -drive file=$DEST.vars,if=pflash,unit=1,format=raw"
  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"

fi

@@ -106,8 +106,8 @@ if [[ "$TPM" == [Yy1]* ]]; then
  if [ ! -S "/run/swtpm-sock" ]; then
    error "TPM socket not found? Disabling TPM module..."
  else
    BOOT_OPTS="$BOOT_OPTS -chardev socket,id=chrtpm,path=/run/swtpm-sock"
    BOOT_OPTS="$BOOT_OPTS -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0"
    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
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ if [[ "${MACHINE,,}" == "pc-i440fx-2"* ]]; then
  DEV_OPTS=""
else
  DEV_OPTS="-object rng-random,id=objrng0,filename=/dev/urandom"
  DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
  [[ "${BOOT_MODE,,}" != "windows"* ]] && DEV_OPTS="$DEV_OPTS -device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
  DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c"
  [[ "${BOOT_MODE,,}" != "windows"* ]] && DEV_OPTS+=" -device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4"
fi

ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $USB_OPTS $NET_OPTS $DISK_OPTS $BOOT_OPTS $DEV_OPTS $ARGUMENTS"
+40 −33
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ supportsDirect() {
}

createDisk() {

  local DISK_FILE=$1
  local DISK_SPACE=$2
  local DISK_DESC=$3
@@ -146,8 +147,8 @@ createDisk() {
    qcow2)

      local DISK_PARAM="$DISK_ALLOC"
      isCow "$FS" && DISK_PARAM="$DISK_PARAM,nocow=on"
      [ -n "$DISK_FLAGS" ] && DISK_PARAM="$DISK_PARAM,$DISK_FLAGS"
      isCow "$FS" && DISK_PARAM+=",nocow=on"
      [ -n "$DISK_FLAGS" ] && DISK_PARAM+=",$DISK_FLAGS"

      if ! qemu-img create -f "$DISK_FMT" -o "$DISK_PARAM" -- "$DISK_FILE" "$DATA_SIZE" ; then
        rm -f "$DISK_FILE"
@@ -167,6 +168,7 @@ createDisk() {
}

resizeDisk() {

  local DISK_FILE=$1
  local DISK_SPACE=$2
  local DISK_DESC=$3
@@ -232,6 +234,7 @@ resizeDisk() {
}

convertDisk() {

  local SOURCE_FILE=$1
  local SOURCE_FMT=$2
  local DST_FILE=$3
@@ -262,18 +265,19 @@ convertDisk() {
    fi
  fi

  html "Converting $DISK_DESC to $DST_FMT..."
  info "Converting $DISK_DESC to $DST_FMT, please wait until completed..."
  local msg="Converting $DISK_DESC to $DST_FMT"
  html "$msg..."
  info "$msg, please wait until completed..."

  local CONV_FLAGS="-p"
  local DISK_PARAM="$DISK_ALLOC"
  isCow "$FS" && DISK_PARAM="$DISK_PARAM,nocow=on"
  isCow "$FS" && DISK_PARAM+=",nocow=on"

  if [[ "$DST_FMT" != "raw" ]]; then
      if [[ "$ALLOCATE" == [Nn]* ]]; then
        CONV_FLAGS="$CONV_FLAGS -c"
        CONV_FLAGS+=" -c"
      fi
      [ -n "$DISK_FLAGS" ] && DISK_PARAM="$DISK_PARAM,$DISK_FLAGS"
      [ -n "$DISK_FLAGS" ] && DISK_PARAM+=",$DISK_FLAGS"
  fi

  # shellcheck disable=SC2086
@@ -302,13 +306,15 @@ convertDisk() {
    fi
  fi

  html "Conversion of $DISK_DESC completed..."
  info "Conversion of $DISK_DESC to $DST_FMT completed succesfully!"
  msg="Conversion of $DISK_DESC"
  html "$msg completed..."
  info "$msg to $DST_FMT completed succesfully!"

  return 0
}

checkFS () {

  local FS=$1
  local DISK_FILE=$2
  local DISK_DESC=$3
@@ -342,6 +348,7 @@ checkFS () {
}

createDevice () {

  local DISK_FILE=$1
  local DISK_TYPE=$2
  local DISK_INDEX=$3
@@ -360,22 +367,22 @@ createDevice () {
      echo "$result"
      ;;
    "usb" )
      result="$result,if=none \
      result+=",if=none \
      -device usb-storage,drive=${DISK_ID}${index}"
      echo "$result"
      ;;
    "ide" )
      result="$result,if=none \
      result+=",if=none \
      -device ide-hd,drive=${DISK_ID},bus=ide.$DISK_INDEX,rotation_rate=$DISK_ROTATION${index}"
      echo "$result"
      ;;
    "blk" | "virtio-blk" )
      result="$result,if=none \
      result+=",if=none \
      -device virtio-blk-pci,drive=${DISK_ID},scsi=off,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2${index}"
      echo "$result"
      ;;
    "scsi" | "virtio-scsi" )
      result="$result,if=none \
      result+=",if=none \
      -device virtio-scsi-pci,id=${DISK_ID}b,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2 \
      -device scsi-hd,drive=${DISK_ID},bus=${DISK_ID}b.0,channel=0,scsi-id=0,lun=0,rotation_rate=$DISK_ROTATION${index}"
      echo "$result"
@@ -386,6 +393,7 @@ createDevice () {
}

addMedia () {

  local DISK_FILE=$1
  local DISK_TYPE=$2
  local DISK_BUS=$3
@@ -402,22 +410,22 @@ addMedia () {
      echo "$result"
      ;;
    "usb" )
      result="$result,if=none \
      result+=",if=none \
      -device usb-storage,drive=${DISK_ID}${index},removable=on"
      echo "$result"
      ;;
    "ide" )
      result="$result,if=none \
      result+=",if=none \
      -device ide-cd,drive=${DISK_ID},bus=ide.${DISK_BUS}${index}"
      echo "$result"
      ;;
    "blk" | "virtio-blk" )
      result="$result,if=none \
      result+=",if=none \
      -device virtio-blk-pci,drive=${DISK_ID},scsi=off,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2${index}"
      echo "$result"
      ;;
    "scsi" | "virtio-scsi" )
      result="$result,if=none \
      result+=",if=none \
      -device virtio-scsi-pci,id=${DISK_ID}b,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2 \
      -device scsi-cd,drive=${DISK_ID},bus=${DISK_ID}b.0${index}"
      echo "$result"
@@ -428,6 +436,7 @@ addMedia () {
}

addDisk () {

  local DISK_BASE=$1
  local DISK_TYPE=$2
  local DISK_DESC=$3
@@ -468,6 +477,7 @@ addDisk () {
    else
      PREV_FMT="qcow2"
    fi

    PREV_EXT=$(fmt2ext "$PREV_FMT")

    if [ -s "$DISK_BASE.$PREV_EXT" ] ; then
@@ -490,12 +500,13 @@ addDisk () {
  fi

  OPTS=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE")
  DISK_OPTS="$DISK_OPTS $OPTS"
  DISK_OPTS+=" $OPTS"

  return 0
}

addDevice () {

  local DISK_DEV=$1
  local DISK_TYPE=$2
  local DISK_INDEX=$3
@@ -506,38 +517,34 @@ addDevice () {

  local OPTS
  OPTS=$(createDevice "$DISK_DEV" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "raw" "$DISK_IO" "$DISK_CACHE")
  DISK_OPTS="$DISK_OPTS $OPTS"
  DISK_OPTS+=" $OPTS"

  return 0
}

DISK_OPTS=""
html "Initializing disks..."

[ -z "$DISK_TYPE" ] && DISK_TYPE="scsi"
[ -z "${DISK_OPTS:-}" ] && DISK_OPTS=""
[ -z "${DISK_TYPE:-}" ] && DISK_TYPE="scsi"

case "${DISK_TYPE,,}" in
  "ide" | "usb" | "scsi" )
    MEDIA_TYPE="$DISK_TYPE" ;;
  "blk" | "auto" )
    MEDIA_TYPE="auto"
    if [ -n "${BOOT_MODE:-}" ] && [[ "${BOOT_MODE:-}" != *"legacy" ]]; then
      [[ "${MACHINE,,}" != "virt" ]] && MEDIA_TYPE="ide"
    fi ;;
  "ide" | "usb" | "scsi" | "blk" | "auto" ) ;;
  * ) error "Invalid DISK_TYPE, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
esac

[[ "${MACHINE,,}" != "virt" ]] && MEDIA_TYPE="ide" || MEDIA_TYPE="auto"

if [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
  DISK_OPTS=$(addMedia "$BOOT" "$MEDIA_TYPE" "0" "$BOOT_INDEX" "0x5")
  ADD_OPTS=$(addMedia "$BOOT" "$MEDIA_TYPE" "0" "$BOOT_INDEX" "0x5")
  DISK_OPTS+=" $ADD_OPTS"
fi

DRIVERS="/drivers.iso"
[ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="$STORAGE/drivers.iso"

if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then
  [[ "${MACHINE,,}" == "virt" ]] && DRIVER_TYPE="auto" || DRIVER_TYPE="ide"
  DRIVER_OPTS=$(addMedia "$DRIVERS" "$DRIVER_TYPE" "1" "" "0x6")
  DISK_OPTS="$DISK_OPTS $DRIVER_OPTS"
  ADD_OPTS=$(addMedia "$DRIVERS" "$MEDIA_TYPE" "1" "" "0x6")
  DISK_OPTS+=" $ADD_OPTS"
fi

DISK1_FILE="$STORAGE/data"
@@ -609,7 +616,7 @@ else
  addDisk "$DISK4_FILE" "$DISK_TYPE" "disk4" "$DISK4_SIZE" "6" "0xd" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE" || exit $?
fi

DISK_OPTS="$DISK_OPTS -object iothread,id=io2"
DISK_OPTS+=" -object iothread,id=io2"

html "Initialized disks successfully..."

+3 −3
Original line number Diff line number Diff line
@@ -31,10 +31,10 @@ fi

[[ "${VGA,,}" == "virtio" ]] && VGA="virtio-vga-gl"
DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128"
DISPLAY_OPTS="$DISPLAY_OPTS -device $VGA"
DISPLAY_OPTS+=" -device $VGA"

[[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0"
[[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS="$DISPLAY_OPTS -vnc :0,websocket=5700"
[[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS+=" -vnc :0"
[[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS+=" -vnc :0,websocket=5700"

[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri

+5 −4
Original line number Diff line number Diff line
@@ -53,10 +53,11 @@ info "$msg..." && html "$msg..."

fKill "progress.sh"

(( rc == 4 )) && error "Failed to download $BOOT , network failure!" && exit 60
(( rc == 8 )) && error "Failed to download $BOOT , server issued an error response!" && exit 60
(( rc != 0 )) && error "Failed to download $BOOT , reason: $rc" && exit 60
[ ! -s "$TMP" ] && error "Failed to download $BOOT" && exit 61
msg="Failed to download $BOOT"
(( rc == 4 )) && error "$msg , network failure!" && exit 60
(( rc == 8 )) && error "$msg , server issued an error response!" && exit 60
(( rc != 0 )) && error "$msg , reason: $rc" && exit 60
[ ! -s "$TMP" ] && error "$msg" && exit 61

html "Download finished successfully..."

Loading