PXE boot over http
This commit is contained in:
96
tools/server
Executable file
96
tools/server
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
ROOT=$(git rev-parse --show-toplevel)
|
||||
|
||||
IPXE_VERSION=b41bda4413bf286d7b7a449bc05e1531da1eec2e
|
||||
IPXE_BIN=(bin/ipxe.pxe bin-x86_64-efi/ipxe.efi)
|
||||
|
||||
IPXE_DIR=${ROOT}/.ipxe/ipxe-${IPXE_VERSION}
|
||||
HTTP_URL=$(cat ${ROOT}/config.yaml | yq .server.httpUrl)
|
||||
|
||||
function download_ipxe() {
|
||||
base_dir=$(dirname ${IPXE_DIR})
|
||||
# Download the iPXE source if needed
|
||||
if [ ! -d "${IPXE_DIR}" ]; then
|
||||
mkdir -p "${base_dir}"
|
||||
curl -L https://github.com/ipxe/ipxe/archive/${IPXE_VERSION}.tar.gz | tar -xz -C "${base_dir}"
|
||||
fi
|
||||
}
|
||||
|
||||
function patch_ipxe() {
|
||||
# Apply patches to iPXE source
|
||||
cd "${IPXE_DIR}/src"
|
||||
sed -i 's/^#undef[\t ]DOWNLOAD_PROTO_HTTPS.*$/#define DOWNLOAD_PROTO_HTTPS/g' config/general.h
|
||||
|
||||
cat > embed.ipxe << EOF
|
||||
#!ipxe
|
||||
|
||||
dhcp
|
||||
chain ${HTTP_URL}/boot.ipxe || shell
|
||||
# chain boot.ipxe || shell
|
||||
EOF
|
||||
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
function build_ipxe() {
|
||||
cd "${IPXE_DIR}/src"
|
||||
for bin in "${IPXE_BIN[@]}"; do
|
||||
path=${IPXE_DIR}/src/${bin}
|
||||
if [ ! -f "${path}" ]; then
|
||||
make -j$(nproc) ${bin} EMBED=embed.ipxe
|
||||
fi
|
||||
done
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
function render() {
|
||||
${ROOT}/tools/render
|
||||
${ROOT}/rendered/generate_configs.sh
|
||||
}
|
||||
|
||||
function host_tftp() {
|
||||
TFTP_DIR=$(mktemp --tmpdir -d tftp.XXX)
|
||||
chmod 755 ${TFTP_DIR}
|
||||
function cleanup() {
|
||||
rm -rf ${TFTP_DIR}
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
cp ${ROOT}/rendered/boot.ipxe ${TFTP_DIR}
|
||||
for bin in "${IPXE_BIN[@]}"; do
|
||||
path=${IPXE_DIR}/src/${bin}
|
||||
cp ${path} ${TFTP_DIR}
|
||||
done
|
||||
|
||||
echo "Starting tftpd"
|
||||
sudo in.tftpd --verbosity 100 --permissive -L --secure ${TFTP_DIR}
|
||||
}
|
||||
|
||||
function host_http() {
|
||||
HTTP_DIR=$(mktemp --tmpdir -d http.XXX)
|
||||
chmod 755 ${HTTP_DIR}
|
||||
function cleanup() {
|
||||
rm -rf ${HTTP_DIR}
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
ln -s ${ROOT}/rendered/boot.ipxe ${HTTP_DIR}
|
||||
for bin in "${IPXE_BIN[@]}"; do
|
||||
path=${IPXE_DIR}/src/${bin}
|
||||
ln -s ${path} ${HTTP_DIR}
|
||||
done
|
||||
|
||||
ln -s ${ROOT}/configs ${HTTP_DIR}
|
||||
|
||||
echo "Starting http"
|
||||
cd ${HTTP_DIR}
|
||||
python -m http.server 8000
|
||||
cd -
|
||||
}
|
||||
|
||||
download_ipxe
|
||||
patch_ipxe
|
||||
build_ipxe
|
||||
render
|
||||
host_http
|
||||
Reference in New Issue
Block a user