Browse Source

Add embedded iPXE script to retry

Currently when the iPXE boot fails, the machine halts and requires
manual intervention to retry. In some environments when machine
boots, but the network is not yet ready to receive the DHCP request
on time. Sometimes when DHCP is ready, the filename option is not
present because the back-end service is not yet ready to provide it.
Then also sometimes the option is there, but it fails.

This patch implements a script which will do ten attempts to get
DHCP and the filename option before failing. When it fails, it will
then reboot the machine. The purpose of this is to maximise the chances
of succeeding the iPXE boot.

A small change to the element deps is also made to ensure that a boot
partition is created. This is necessary due to changes in

Finally, the git SHA is updated in the make file to the current HEAD
to ensure that the image built is current.

Change-Id: Iccef8ff21b64f20f4a185c654c0308478eecfb4a
Jesse Pretorius (odyssey4me) 3 months ago

+ 3
- 1
ipxe/Makefile View File

@@ -1,5 +1,7 @@
# git ref to checkout from the iPXE git repository
# This is the current SHA for HEAD on 9 Aug 2019


ELEMENTS_PATH=./elements IPXE_GIT_REF=$(IPXE_GIT_REF) disk-image-create -x -o ipxe-boot ipxe-boot-image

+ 1
- 0
ipxe/elements/ipxe-boot-image/element-deps View File

@@ -1,2 +1,3 @@

+ 51
- 1
ipxe/elements/ipxe-boot-image/install.d/50-grub2-boot-ipxe View File

@@ -29,7 +29,57 @@ if [ -n "${IPXE_GIT_REF:-}" ]; then
IPXE_GIT_REF_CURRENT=$(git rev-parse --short HEAD)

make bin/ipxe.lkrn
cat << EOF >>script.ipxe
# This is the iPXE boot script that we embed into the iPXE binary.
# The default behaviour is to get DHCP and assume that DHCP includes
# the filename option. If it fails, then it just stops.
# This script implements more retries until both DHCP and the filename
# option are present. This makes sure that the underlying network has
# plenty of time to be ready. If this still fails, then rather than
# halt, then host will reboot to try again.
# Based on:
set attempts:int32 10
set x:int32 0

dhcp || goto nodhcp
isset \${filename} || goto nobootconfig
goto boot

echo No DHCP response, retrying (attempt \${x}/\${attempts}).
sleep 1
goto retry

echo No filename option present, retrying (attempt \${x}/\${attempts}).
sleep 1
goto retry

iseq \${x} \${attempts} && goto fail ||
inc x
goto loop

chain \${filename}

echo Failed to get a correct DHCP response after \${attempts} attempts.
echo Rebooting in 5 seconds...
sleep 5

make bin/ipxe.lkrn EMBED=script.ipxe
cp bin/ipxe.lkrn /boot/

cat << EOF >>/etc/grub.d/40_custom

ipxe/ipxe-boot.qcow2 View File