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

feat: Allow booting without ISO file (#521)

parent 81153086
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ kubectl apply -f kubernetes.yml
  
  This can also be used to resize the existing disk to a larger capacity without any data loss.

* ### How do I boot a local image?
* ### How do I boot a local ISO?

  You can use a local file directly, and skip the download altogether, by binding it in your compose file in this way:
  
@@ -97,7 +97,20 @@ kubectl apply -f kubernetes.yml
    - /home/user/example.iso:/boot.iso
  ```

  Replace the example path `/home/user/example.iso` with the filename of the desired ISO file.
  Replace the example path `/home/user/example.iso` with the filename of the desired ISO file, the value of `BOOT` will be ignored in this case.

* ### How do I boot without SCSI support?

  By default, the machine makes use of `virtio-scsi` disks for performance reasons, and even though most Linux kernels include drivers for them, there are other operating systems that do not.

  If your ISO fails to boot because of this, you can add this to your compose file:

  ```yaml
  environment:
    DISK_TYPE: "blk"
  ```

   This will use `virtio-blk` devices instead. If it still fails to boot, you can set the value to `ide` to use IDE disks which every OS will support, at the cost of performance.

* ### How do I boot with UEFI?

@@ -108,6 +121,10 @@ kubectl apply -f kubernetes.yml
    BOOT_MODE: "uefi"
  ```

* ### How do I boot ARM images?

  You can use [qemu-arm](https://github.com/qemus/qemu-arm/) to run ARM64-based images.

* ### How do I boot Windows?

  To enable Windows booting, add the following line to your compose file:
@@ -119,10 +136,6 @@ kubectl apply -f kubernetes.yml

  But you might want to give [dockur/windows](https://github.com/dockur/windows) a try instead, as it includes all the drivers required during installation amongst many other features.

* ### How do I boot a ARM-based image?

  You can use [qemu-arm](https://github.com/qemus/qemu-arm/) to run ARM64 images.

* ### How do I verify if my system supports KVM?

  To verify if your system supports KVM, run the following commands:
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ set -Eeuo pipefail

BOOT_DESC=""
BOOT_OPTS=""
DRIVER_TYPE="ide"
SECURE=",smm=off"

if [[ "${BOOT_MODE,,}" == "windows"* ]]; then
+1 −1
Original line number Diff line number Diff line
@@ -530,7 +530,7 @@ DRIVERS="/drivers.iso"
[ ! -f "$DRIVERS" ] || [ ! -s "$DRIVERS" ] && DRIVERS="/run/drivers.iso"

if [ -f "$DRIVERS" ] && [ -s "$DRIVERS" ]; then
  DRIVER_OPTS=$(addMedia "$DRIVERS" "ide" "1" "" "0x6")
  DRIVER_OPTS=$(addMedia "$DRIVERS" "$DRIVER_TYPE" "1" "" "0x6")
  DISK_OPTS="$DISK_OPTS $DRIVER_OPTS"
fi

+31 −17
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -Eeuo pipefail

# Check if running with interactive TTY or redirected to docker log
if [ -t 1 ]; then
  progress="--progress=bar:noscroll"
else
  progress="--progress=dot:giga"
fi
file=$(find / -maxdepth 1 -type f -iname boot.iso | head -n 1)
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso | head -n 1)

file="/boot.iso" && [ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
file="/boot.img" && [ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
if [ ! -s "$file" ] && [[ "${BOOT,,}" != "http"* ]]; then
  local base=$(basename "$BOOT")
  file="$STORAGE/$base"
fi

file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso -printf "%f\n" | head -n 1)
[ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.img -printf "%f\n" | head -n 1)
[ -n "$file" ] && file="$STORAGE/$file" 
[ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
if [ -f "$file" ] && [ -s "$file" ]; then
  BOOT="$file"
  return 0
fi

if [ -z "$BOOT" ]; then
  hasDisk && return 0
  error "No boot disk specified, set BOOT= to the URL of an ISO file." && exit 64
fi

base=$(basename "$BOOT")
[ -n "$base" ] && file="$STORAGE/$base" 
[ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
file="$STORAGE/$base" 

if [ -f "$file" ] && [ -s "$file" ]; then
  BOOT="$file"
  return 0
fi

base=$(basename "${BOOT%%\?*}")
: "${base//+/ }"; printf -v base '%b' "${_//%/\\x}"
base=$(echo "$base" | sed -e 's/[^A-Za-z0-9._-]/_/g')
[ -n "$base" ] && file="$STORAGE/$base" 
[ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
file="$STORAGE/$base" 

if [ -f "$file" ] && [ -s "$file" ]; then
  BOOT="$file"
  return 0
fi

TMP="$STORAGE/${base%.*}.tmp"
rm -f "$TMP"

# Check if running with interactive TTY or redirected to docker log
if [ -t 1 ]; then
  progress="--progress=bar:noscroll"
else
  progress="--progress=dot:giga"
fi

msg="Downloading $base..."
info "$msg" && html "$msg"

/run/progress.sh "$TMP" "" "Downloading $base ([P])..." &
{ wget "$BOOT" -O "$TMP" -q --timeout=10 --show-progress "$progress"; rc=$?; } || :
{ wget "$BOOT" -O "$TMP" -q --timeout=30 --show-progress "$progress"; rc=$?; } || :

fKill "progress.sh"

+11 −0
Original line number Diff line number Diff line
@@ -190,6 +190,17 @@ addPackage() {
  return 0
}

hasDisk() {

  [ -b "/disk1" ] && return 0
  [ -b "/dev/disk1" ] && return 0
  [ -b "${DEVICE:-}" ] && return 0
  [ -s "$STORAGE/data.img" ]  && return 0
  [ -s "$STORAGE/data.qcow2" ] && return 0

  return 1
}

# Start webserver
cp -r /var/www/* /run/shm
html "Starting $APP for Docker..."