Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Automaticly enable UEFI based on ISO #523

Merged
merged 15 commits into from
May 22, 2024
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ARG DEBIAN_FRONTEND="noninteractive"
ARG DEBCONF_NONINTERACTIVE_SEEN="true"

RUN set -eu && \

Check failure on line 10 in Dockerfile

View workflow job for this annotation

GitHub Actions / Test / shellcheck

SC2035 info: Use ./*glob* or -- *glob* so names with dashes won't become options.
apt-get update && \
apt-get --no-install-recommends -y install \
tini \
Expand All @@ -22,6 +22,7 @@
dnsmasq \
net-tools \
qemu-utils \
genisoimage \
ca-certificates \
netcat-openbsd \
qemu-system-x86 && \
Expand Down
34 changes: 9 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,26 @@ kubectl apply -f kubernetes.yml

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?

To enable UEFI booting, add the following line to your compose file:

```yaml
environment:
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:
Use [dockur/windows](https://github.com/dockur/windows) instead, as it includes all the drivers required during installation, amongst many other features.

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

By default, the machine makes use of `virtio-scsi` disks for performance reasons, and even though most Linux kernels include the necessary driver for this device, for some other operating systems that may not always be the case.

If your ISO fails to boot because of this, you can modify your compose file to use `virtio-blk` instead:

```yaml
environment:
BOOT_MODE: "windows"
DISK_TYPE: "blk"
```

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.
If it still fails to boot, you can set the value to `ide` to emulate a IDE drive, which is slow but compatible with almost every system.

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

Expand Down
6 changes: 0 additions & 6 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ if [[ "${BOOT_MODE,,}" == "windows"* ]]; then
BOOT_OPTS="$BOOT_OPTS -global ICH9-LPC.disable_s3=1"
BOOT_OPTS="$BOOT_OPTS -global ICH9-LPC.disable_s4=1"

if [ -e /sys/module/kvm/parameters/ignore_msrs ]; then
if [ "$(cat /sys/module/kvm/parameters/ignore_msrs)" == "N" ]; then
echo 1 | tee /sys/module/kvm/parameters/ignore_msrs > /dev/null 2>&1 || true
fi
fi

fi

case "${BOOT_MODE,,}" in
Expand Down
43 changes: 21 additions & 22 deletions src/install.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
#!/usr/bin/env bash
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)
detect () {
local dir=""
local file="$1"
[ ! -f "$file" ] && return 1
[ ! -s "$file" ] && return 1

if [ ! -s "$file" ] && [[ "${BOOT,,}" != "http"* ]]; then
base=$(basename "$BOOT")
file="$STORAGE/$base"
fi
dir=$(isoinfo -f -i "$file")

# Automaticly detect UEFI-compatible ISO's
if echo "${dir^^}" | grep -q "^/EFI"; then
[ -z "${BOOT_MODE:-}" ] && BOOT_MODE="uefi"
fi

if [ -f "$file" ] && [ -s "$file" ]; then
BOOT="$file"
return 0
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)
detect "$file" && return 0

if [ -z "$BOOT" ]; then
if [ -z "$BOOT" ] || [[ "$BOOT" == *"example.com/image.iso" ]]; 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
detect "$STORAGE/$base" && return 0

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
detect "$STORAGE/$base" && return 0

TMP="$STORAGE/${base%.*}.tmp"
rm -f "$TMP"
Expand Down Expand Up @@ -67,6 +65,7 @@ if ((size<100000)); then
error "Invalid ISO file: Size is smaller than 100 KB" && exit 62
fi

mv -f "$TMP" "$file"
mv -f "$TMP" "$STORAGE/$base"
! detect "$STORAGE/$base" && exit 63

return 0
6 changes: 3 additions & 3 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,16 @@ if [[ "$DHCP" == [Yy1]* ]]; then

! checkOS && [[ "$DEBUG" != [Yy1]* ]] && exit 19

if [[ "$GATEWAY" == "172."* ]]; then
warn "your gateway IP starts with 172.* which is often a sign that you are not on a macvlan network (required for DHCP)!"
if [[ "$IP" == "172."* ]]; then
warn "container IP starts with 172.* which is often a sign that you are not on a macvlan network (required for DHCP)!"
fi

# Configuration for DHCP IP
configureDHCP

else

if [[ "$GATEWAY" != "172."* ]] && [[ "$GATEWAY" != "10.8"* ]] && [[ "$GATEWAY" != "10.9"* ]]; then
if [[ "$IP" != "172."* ]] && [[ "$IP" != "10.8"* ]] && [[ "$IP" != "10.9"* ]]; then
! checkOS && [[ "$DEBUG" != [Yy1]* ]] && exit 19
fi

Expand Down
6 changes: 6 additions & 0 deletions src/proc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ if [[ "$KVM" != [Nn]* ]]; then
CPU_FEATURES="$CPU_FEATURES,migratable=no"
fi

if [ -e /sys/module/kvm/parameters/ignore_msrs ]; then
if [ "$(cat /sys/module/kvm/parameters/ignore_msrs)" == "N" ]; then
echo 1 | tee /sys/module/kvm/parameters/ignore_msrs > /dev/null 2>&1 || true
fi
fi

if [[ "$HV" != [Nn]* ]] && [[ "${BOOT_MODE,,}" == "windows"* ]]; then

HV_FEATURES="+hypervisor,hv_passthrough"
Expand Down