From 7f42cdc8b5900c0a19a2ff77985d0a7d026fd13a Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Sat, 23 Dec 2023 02:39:08 -0700 Subject: [PATCH] Update iPXE build script Replace `ipxe-update.sh` with `scripts/build-ipxe.sh`. * correctly builds for arm64 * supports additional configuration from environment variables * intended for use on an installed system Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + README.md | 32 ++++++++++-- ipxe-update.sh | 111 ------------------------------------------ scripts/build-ipxe.sh | 99 +++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 115 deletions(-) delete mode 100755 ipxe-update.sh create mode 100755 scripts/build-ipxe.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index e14206a4..db295d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -124,6 +124,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow absolute iPXE paths in warewulf.conf - Support importing containers with symlinked `/bin/sh` #797 - Don't panic on malformed passwd #527 +- Update iPXE building script ## [4.4.0] 2023-01-18 diff --git a/README.md b/README.md index 0ee8c705..95f86709 100644 --- a/README.md +++ b/README.md @@ -68,14 +68,38 @@ no matter how big or small or customized it needs to be. ## iPXE Warewulf uses iPXE for network boot. Typically iPXE is provided by the -operating system; but the iPXE binaries can be rebuilt with the -`ipxe-update.sh` script. This script accepts command-line arguments -that are passed to the underlying `make` process. e.g., +operating system; but the iPXE binaries can be built with +`scripts/build-ipxe.sh`. This script accepts command-line arguments that are +passed to the underlying `make` process. e.g., ```bash + echo "#!ipxe echo Tagging with vlan 1000 vcreate --tag 1000 net0 autoboot || shell" >vlan-1000.ipxe -sh ipxe-update.sh EMBED=$(readlink -f vlan-1000.ipxe) +sh scripts/build-ipxe.sh EMBED=$(readlink -f vlan-1000.ipxe) +``` + +By default, `build-ipxe.sh` will attempt to write iPXE builds to +`/usr/local/share/ipxe/`. This path can be specified using the `DESTDIR` +environment variable. Other supported environment variables include +`IPXE_BRANCH` and `TARGETS`. + +```bash + +IPXE_BRANCH=master TARGETS=bin-arm64-efi/snponly.efi DESTDIR=. sh scripts/build-ipxe.sh +``` + +Update `warewulf.conf` to use locally-built iPXE. + +``` +tftp: + enabled: true + systemd name: tftp + ipxe: + 00:09: /usr/local/share/ipxe/bin-x86_64-efi-snponly.efi + 00:00: /usr/local/share/ipxe/bin-x86_64-pcbios-undionly.kpxe + 00:0B: /usr/local/share/ipxe/bin-arm64-efi-snponly.efi + 00:07: /usr/local/share/ipxe/bin-x86_64-efi-snponly.efi ``` diff --git a/ipxe-update.sh b/ipxe-update.sh deleted file mode 100755 index 1db450a5..00000000 --- a/ipxe-update.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/sh -# Builds ipxe binaries from github sources or given tarball - -VERSION=v1.21.1 - -ARCH=x86_64 - -PCBIOS=bin-${ARCH}-pcbios/undionly.kpxe -EFI=bin-${ARCH}-efi/ipxe.efi - -PCBIOS_output=${ARCH}.kpxe -EFI_output=${ARCH}.efi - -SYSBIOS="/usr/share/ipxe/undionly.kpxe" -SYSEFI="/usr/share/ipxe/ipxe-${ARCH}.efi" - -TMPDIR=`mktemp -d /tmp/ipxebuild.XXXXXX` - -usage() { - echo "Usage: $(basename $0) - [-s] (install efi and bios from system location) - [-g] (build from git repo and install built efi and bios) - [-h] (help) - [-f] ipxe_source_gz_file (build from given tar.gz ipxe file and install built efi and bios) - " - exit 1 -} - -sysbuild() { - if [ -f "${SYSEFI}" ] ; then - cp $SYSEFI $EFI_output - else - echo "No such file or directory: ${SYSEFI}, try 'dnf install ipxe-bootimgs-x86'" - exit 1 - fi - - if [ -f "${SYSBIOS}" ] ; then - cp $SYSBIOS $PCBIOS_output - else - echo "No such file or directory: ${SYSBIOS}, try 'dnf install ipxe-bootimgs-x86'" - exit 1 - fi - - echo "copy ${SYSEFI} and ${SYSBIOS} done" -} - -gitbuild() { - cd "$TMPDIR" - git clone --depth 1 --branch $VERSION https://github.com/ipxe/ipxe.git - build -} - -filebuild() { - TARGET_PATH=$1 - case $TARGET_PATH in - /*) ;; - *) - TARGET_PATH=`pwd`/$TARGET_PATH - ;; - esac - if [ -f "${TARGET_PATH}" ] ; then - cd "$TMPDIR" - tar xzf $TARGET_PATH - build $TARGET_PATH - else - echo "No such file $TARGET_PATH" - exit 1 - fi -} - -build() { - cd ipxe*/src - - sed -i.bak \ - -e 's,//\(#define.*CONSOLE_SERIAL.*\),\1,' \ - -e 's,//\(#define.*CONSOLE_FRAMEBUFFER.*\),\1,' \ - config/console.h - - sed -i.bak \ - -e 's,//\(#define.*IMAGE_ZLIB.*\),\1,' \ - -e 's,//\(#define.*IMAGE_GZIP.*\),\1,' \ - -e 's,//\(#define.*VLAN_CMD.*\),\1,' \ - config/general.h - - make -j 8 $PCBIOS "$@" - make -j 8 $EFI "$@" - - cp $PCBIOS $PCBIOS_output - cp $EFI $EFI_output - - echo "copy ${PCBIOS} and ${EFI} done" -} - -while getopts 'sghdf:' c -do - case $c in - s) sysbuild - break - ;; - g) gitbuild - break - ;; - f) filebuild $OPTARG - break - ;; - h|*) usage - ;; - esac -done - -rm -rf "$TMPDIR" diff --git a/scripts/build-ipxe.sh b/scripts/build-ipxe.sh new file mode 100755 index 00000000..7431b893 --- /dev/null +++ b/scripts/build-ipxe.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +set -e + +TARGETS=${TARGETS:-"bin-x86_64-pcbios/undionly.kpxe bin-x86_64-efi/snponly.efi bin-arm64-efi/snponly.efi"} +IPXE_BRANCH=${IPXE_BRANCH:-master} +DESTDIR=${DESTDIR:-/usr/local/share/ipxe} + +CPUS=$(grep 'processor.*:' /proc/cpuinfo | wc -l) + + +function usage { + echo "Usage: $(basename $0) + [-h] (help) + +TARGETS: ${TARGETS} +IPXE_BRANCH: ${IPXE_BRANCH} +DESTDIR: ${DESTDIR}" + exit 1 +} + + +function main { + local DESTDIR=$(readlink -f ${DESTDIR}) + + while getopts 'h' c + do + case $c in + h|*) usage + ;; + esac + done + + TMPDIR=`mktemp -d /tmp/ipxebuild.XXXXXX` + trap "rm -rf $TMPDIR" EXIT + cd "$TMPDIR" + + git clone --branch "${IPXE_BRANCH}" https://github.com/ipxe/ipxe.git + + cd ipxe/src + + for target in ${TARGETS} + do + if $(echo "$target" | grep -q "\-arm64-") + then + if ! which aarch64-linux-gnu-gcc >/dev/null 2>&1 + then + echo 1>&2 "aarch64-linux-gnu-gcc not found: not building for arm64" + continue + fi + CROSS=aarch64-linux-gnu- + configure_arm64 + else + CROSS="" + configure_x86_64 + fi + destname=$(echo $target | tr / -) + make -j $CPUS CROSS="${CROSS}" $target "$@" && cp -v $target ${DESTDIR}/${destname} + restore_config + done +} + + +function configure_arm64 { + # CONSOLE_SERIAL causes build failure for aarch64, so omitting here + # https://github.com/ipxe/ipxe/issues/658 + sed -i.bak \ + -e 's,//\(#define.*CONSOLE_FRAMEBUFFER.*\),\1,' \ + config/console.h + + sed -i.bak \ + -e 's,//\(#define.*IMAGE_ZLIB.*\),\1,' \ + -e 's,//\(#define.*IMAGE_GZIP.*\),\1,' \ + -e 's,//\(#define.*VLAN_CMD.*\),\1,' \ + config/general.h +} + + +function configure_x86_64 { + sed -i.bak \ + -e 's,//\(#define.*CONSOLE_SERIAL.*\),\1,' \ + -e 's,//\(#define.*CONSOLE_FRAMEBUFFER.*\),\1,' \ + config/console.h + + sed -i.bak \ + -e 's,//\(#define.*IMAGE_ZLIB.*\),\1,' \ + -e 's,//\(#define.*IMAGE_GZIP.*\),\1,' \ + -e 's,//\(#define.*VLAN_CMD.*\),\1,' \ + config/general.h +} + + +function restore_config { + cp config/console.h{.bak,} + cp config/general.h{.bak,} +} + + +main "$@"