-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.ipxe
67 lines (59 loc) · 2.07 KB
/
boot.ipxe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!ipxe
#
# This is the iPXE boot script that we embed into the iPXE binary.
#
# The entire reason for the existence of this script is that iPXE very
# eagerly configures DHCP as soon as it gets a DHCP response, and
# because of this it might miss the ProxyDHCP response that tells it
# how to boot. In this situation, `autoboot` (the default command)
# just fails and falls out of the PXE boot codepath, so we end up with
# machines that sometimes fail to "catch" the network boot.
#
# This script implements what the ipxe documentation recommends, which
# is to just retry the `dhcp` command a bunch until ipxe does see a
# ProxyDHCP response. It's quite ugly, and a proper fix should really
# get upstreamed to ipxe, but for right now, this works.
set attempts:int32 10
set x:int32 0
set user-class pixiecore
# Try to get a filename from ProxyDHCP, retrying a couple of times if
# we fail.
:loop
dhcp || goto nodhcp
isset ${filename} || goto nobootconfig
goto boot
:nodhcp
echo No DHCP response, retrying (attempt ${x}/${attempts})
goto retry
:nobootconfig
echo No ProxyDHCP response, retrying (attempt ${x}/${attempts})
goto retry
:retry
iseq ${x} ${attempts} && goto fail ||
inc x
goto loop
# Got a filename from ProxyDHCP, that's the actual boot script,
# off we go!
:boot
chain ${filename}
# Failure at this point probably means Pixiecore changed its mind
# about whether this machine should be booted in the middle of the
# boot cycle, so we had already handed off to iPXE, but now we're
# no longer serving a boot script for it.
#
# Reboot the machine to restart the whole cycle (and presumably skip
# PXE completely this time).
#
# It's also possible we just got horribly unlucky and the network
# environment is such that we're consistently missing the ProxyDHCP
# reply. That really sucks, so give people pointers to bug filing
# here.
:fail
echo Failed to get a ProxyDHCP response after ${attempts} attempts
echo
echo If you are sure that Pixiecore is still trying to boot this machine,
echo please file a bug at https://github.com/google/netboot .
echo
echo Rebooting in 5 seconds...
sleep 5
reboot