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 <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2023-12-23 02:39:08 -07:00
parent 72b7f0aa5c
commit 7f42cdc8b5
4 changed files with 128 additions and 115 deletions

View File

@@ -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

View File

@@ -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
```

View File

@@ -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"

99
scripts/build-ipxe.sh Executable file
View File

@@ -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 "$@"