feat: Allow booting without ISO file (#87)
This commit is contained in:
parent
95b8acc301
commit
e9087a6eb3
5 changed files with 67 additions and 29 deletions
17
readme.md
17
readme.md
|
@ -91,7 +91,7 @@ kubectl apply -f kubernetes.yml
|
||||||
|
|
||||||
This can also be used to resize the existing disk to a larger capacity without any data loss.
|
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:
|
You can use a local file directly, and skip the download altogether, by binding it in your compose file in this way:
|
||||||
|
|
||||||
|
@ -100,7 +100,20 @@ kubectl apply -f kubernetes.yml
|
||||||
- /home/user/example.iso:/boot.iso
|
- /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` or `usb` at the cost of performance.
|
||||||
|
|
||||||
* ### How do I boot a x86 image?
|
* ### How do I boot a x86 image?
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ set -Eeuo pipefail
|
||||||
|
|
||||||
BOOT_OPTS=""
|
BOOT_OPTS=""
|
||||||
BOOT_DESC=""
|
BOOT_DESC=""
|
||||||
|
DRIVER_TYPE="usb"
|
||||||
SECURE=",secure=off"
|
SECURE=",secure=off"
|
||||||
DIR="/usr/share/qemu"
|
DIR="/usr/share/qemu"
|
||||||
|
|
||||||
|
|
|
@ -514,7 +514,6 @@ case "${DISK_TYPE,,}" in
|
||||||
* ) error "Invalid DISK_TYPE, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
|
* ) error "Invalid DISK_TYPE, value \"$DISK_TYPE\" is unrecognized!" && exit 80 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
DRIVER_TYPE="usb"
|
|
||||||
MEDIA_TYPE="$DISK_TYPE"
|
MEDIA_TYPE="$DISK_TYPE"
|
||||||
|
|
||||||
if [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
|
if [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
|
||||||
|
|
|
@ -1,6 +1,45 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
if [ ! -s "$file" ] && [[ "${BOOT,,}" != "http"* ]]; then
|
||||||
|
base=$(basename "$BOOT")
|
||||||
|
file="$STORAGE/$base"
|
||||||
|
fi
|
||||||
|
|
||||||
|
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")
|
||||||
|
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')
|
||||||
|
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
|
# Check if running with interactive TTY or redirected to docker log
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
progress="--progress=bar:noscroll"
|
progress="--progress=bar:noscroll"
|
||||||
|
@ -8,36 +47,11 @@ else
|
||||||
progress="--progress=dot:giga"
|
progress="--progress=dot:giga"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
file="/boot.iso" && [ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
|
|
||||||
file="/boot.img" && [ -f "$file" ] && [ -s "$file" ] && BOOT="$file" && return 0
|
|
||||||
|
|
||||||
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 [ -z "$BOOT" ]; then
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
TMP="$STORAGE/${base%.*}.tmp"
|
|
||||||
rm -f "$TMP"
|
|
||||||
|
|
||||||
msg="Downloading $base..."
|
msg="Downloading $base..."
|
||||||
info "$msg" && html "$msg"
|
info "$msg" && html "$msg"
|
||||||
|
|
||||||
/run/progress.sh "$TMP" "" "Downloading $base ([P])..." &
|
/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"
|
fKill "progress.sh"
|
||||||
|
|
||||||
|
|
11
src/reset.sh
11
src/reset.sh
|
@ -191,6 +191,17 @@ addPackage() {
|
||||||
return 0
|
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
|
# Start webserver
|
||||||
cp -r /var/www/* /run/shm
|
cp -r /var/www/* /run/shm
|
||||||
html "Starting $APP for Docker..."
|
html "Starting $APP for Docker..."
|
||||||
|
|
Loading…
Reference in a new issue