Project

General

Profile

Fetch boot files via http instead of TFTP » History » Version 14

Lukas Zapletal, 02/16/2016 06:32 AM

1 10 Lukas Zapletal
h1. PXELinux chainboot into iPXE
2 1 Alexander Chuzhoy
3 14 Lukas Zapletal
{{toc}}
4
5 10 Lukas Zapletal
TFTP is a slow protocol on high-latency networks, but if your hardware is supported by iPXE (http://ipxe.org/appnote/hardware_drivers) or if UNDI driver of the NIC is compatible with iPXE, it is possible to configure PXELinux to chainboot iPXE and continue booting via HTTP protocol which is fast and reliable.
6 1 Alexander Chuzhoy
7 10 Lukas Zapletal
In this scenario, a system is PXE-booted into PXELinux which chainloads iPXE which continue booting via HTTP. The scenario is:
8
9
* hardware is turned on
10
* PXE driver gets network credentials from DHCP
11
* PXE driver gets PXELinux firmware from TFTP (pxelinux.0)
12
* PXELinux searches for configuration file on TFTP
13
* PXELinux chainloads iPXE (undionly-ipxe.0 or ipxe.lkrn)
14
* iPXE gets network credentials from DHCP again
15
* iPXE gets HTTP address from DHCP
16
* iPXE chainloads the iPXE template from Foreman
17
* iPXE loads kernel and init RAM disk of the installer
18
19
Requirements:
20
21
* a host entry is created in Foreman
22
* MAC address of the provisioning interface matches
23
* provisioning interface of the host has a valid DHCP reservation
24
* the host has special PXELinux template (below) associated
25
* the host has iPXE template associated
26
* hardware is capable of PXE booting
27
* hardware NIC is compatible with iPXE
28
29
The iPXE project offers two options: using PXE interface (UNDI) or using built-in linux network card driver. Both options have pros and cons and each gives different results with different hardware cards. Some NIC adapters can be slow with UNDI, some are actually faster. Not all network cards will work with either or both ways.
30
31 13 Lukas Zapletal
h2. A. Chainbooting iPXE directly
32 10 Lukas Zapletal
33 12 Lukas Zapletal
In this setup, iPXE uses build-in driver for network communication. Therefore this will only work on supported cards (see above)!
34 10 Lukas Zapletal
35 12 Lukas Zapletal
h3. TFTP setup
36 10 Lukas Zapletal
37 12 Lukas Zapletal
Copy the iPXE firmware to the TFTP root directory:
38 10 Lukas Zapletal
39 12 Lukas Zapletal
  cp /usr/share/ipxe/ipxe.lkrn /var/lib/tftpboot/
40 10 Lukas Zapletal
41 12 Lukas Zapletal
The source directory can be different on linux distributions, this is for Red Hats. The file is shipped in ipxe-bootimgs package.
42 1 Alexander Chuzhoy
43 12 Lukas Zapletal
Do not use symbolic links as TFTP runs in chroot. When using SELinux, remember to correct file contexts:
44 1 Alexander Chuzhoy
45 12 Lukas Zapletal
  restorecon -RvF /var/lib/tftpboot/
46 1 Alexander Chuzhoy
47 12 Lukas Zapletal
h3. Foreman setup - PXELinux template
48 1 Alexander Chuzhoy
49 12 Lukas Zapletal
Configuration involves associating PXELinux and iPXE templates.
50 1 Alexander Chuzhoy
51 12 Lukas Zapletal
In your Foreman instance, go to "Provisioning templates" and create new template of PXELinux kind with the following contents:
52 1 Alexander Chuzhoy
53 12 Lukas Zapletal
<pre><code>
54
DEFAULT linux
55
LABEL linux
56
KERNEL ipxe.lkrn
57
APPEND dhcp && chain <%= foreman_url('iPXE') %>
58
IPAPPEND 2
59
</code></pre>
60 1 Alexander Chuzhoy
61 12 Lukas Zapletal
Recent version of Foreman ships with this template already under name "PXELinux chain iPXE".
62 1 Alexander Chuzhoy
63 12 Lukas Zapletal
h3. Foreman setup - iPXE template
64 1 Alexander Chuzhoy
65 12 Lukas Zapletal
Associate iPXE template which ships with Foreman which is named 'Kickstart default iPXE' or 'Preseed default iPXE' containing something like:
66 1 Alexander Chuzhoy
67 12 Lukas Zapletal
<pre><code>#!ipxe
68
kernel <%= "#{@host.url_for_boot(:kernel)}" %> ks=<%= foreman_url("provision")%>
69
initrd <%= "#{@host.url_for_boot(:initrd)}" %>
70
boot
71
</code></pre>
72 10 Lukas Zapletal
73 12 Lukas Zapletal
If there was a host associated with PXELinux templates, you may need to exit and re-enter Build state for the TFTP configuration to be redeployed. Recent versions of Foreman do this automatically on template save.
74
75 13 Lukas Zapletal
h2. B. Chainbooting iPXE via UNDI
76 12 Lukas Zapletal
77
In this setup, iPXE uses UNDI for network communication. The hardware must support that.
78
79
h3. TFTP setup
80
81
Copy the iPXE firmware to the TFTP root directory and rename it:
82
83
  cp /usr/share/ipxe/undionly.kpxe /var/lib/tftpboot/undionly-ipxe.0
84
85
The source directory can be different on linux distributions, this is for Red Hats. The file is shipped in ipxe-bootimgs package.
86
87 1 Alexander Chuzhoy
Do not use symbolic links as TFTP runs in chroot. When using SELinux, remember to correct file contexts:
88 10 Lukas Zapletal
89 9 Lukas Zapletal
  restorecon -RvF /var/lib/tftpboot/
90 1 Alexander Chuzhoy
91 12 Lukas Zapletal
h3. TFTP setup (gPXELinux alternative)
92 10 Lukas Zapletal
93 12 Lukas Zapletal
This is alternative approach if none of the above configurations work or packages are not available.
94 10 Lukas Zapletal
95 12 Lukas Zapletal
Copy the gPXE firmware to the TFTP root directory:
96 10 Lukas Zapletal
97 12 Lukas Zapletal
  cp /usr/share/syslinux/gpxelinuxk.0 /var/lib/tftpboot/
98
99
The source directory can be different on linux distributions, this is for Red Hats. The file is shipped in syslinux package.
100
101
Do not use symbolic links as TFTP runs in chroot. When using SELinux, remember to correct file contexts:
102
103
  restorecon -RvF /var/lib/tftpboot/
104
105
h3. Foreman setup - PXELinux template
106
107 9 Lukas Zapletal
In your Foreman instance, go to "Provisioning templates" and create new template of PXELinux kind with the following contents:
108
109 1 Alexander Chuzhoy
<pre><code>
110
DEFAULT undionly-ipxe
111 9 Lukas Zapletal
LABEL undionly-ipxe
112 1 Alexander Chuzhoy
MENU LABEL iPXE UNDI
113
KERNEL undionly-ipxe.0
114 10 Lukas Zapletal
IPAPPEND 2
115 9 Lukas Zapletal
</code></pre>
116 1 Alexander Chuzhoy
117
Recent version of Foreman ships with this template already under name "PXELinux chain iPXE UNDI".
118
119 12 Lukas Zapletal
h3. Foreman setup - iPXE template
120 1 Alexander Chuzhoy
121 12 Lukas Zapletal
Associate iPXE template which ships with Foreman which is named 'Kickstart default iPXE' or 'Preseed default iPXE' containing something like:
122 1 Alexander Chuzhoy
123
<pre><code>#!ipxe
124
kernel <%= "#{@host.url_for_boot(:kernel)}" %> ks=<%= foreman_url("provision")%>
125
initrd <%= "#{@host.url_for_boot(:initrd)}" %>
126
boot
127
</code></pre>
128
129
If there was a host associated with PXELinux templates, you may need to exit and re-enter Build state for the TFTP configuration to be redeployed. Recent versions of Foreman do this automatically on template save.
130
131 12 Lukas Zapletal
h3. DHCP setup
132 1 Alexander Chuzhoy
133
The above configuration will lead to an endless loop of chainbooting iPXE firmware. To break this loop, configure DHCP server to hand over correct URL to iPXE to continue booting. In the /etc/dhcp/dhcpd.conf file change the "filename" global or subnet configuration as follows:
134
135 10 Lukas Zapletal
<pre><code>
136 9 Lukas Zapletal
if exists user-class and option user-class = "iPXE" {
137 13 Lukas Zapletal
  filename "https://foreman:443/unattended/iPXE";
138 1 Alexander Chuzhoy
} else {
139
  filename "pxelinux.0";
140
}
141
</code></pre>
142
143 12 Lukas Zapletal
On isolated networks, use Smart Proxy URL instead of Foreman when templates feature is enabled. If there are existing leases on the DHCP server, let them expire and restart the DHCP service. This can be also forced with
144 1 Alexander Chuzhoy
145 10 Lukas Zapletal
<pre><code>
146 1 Alexander Chuzhoy
truncate /var/lib/dhcpd/dhcpd.leases
147 10 Lukas Zapletal
service dhcpd restart
148
</code></pre>
149 11 Lukas Zapletal
150 13 Lukas Zapletal
h2. C. Chainbooting virtual machines
151 10 Lukas Zapletal
152 12 Lukas Zapletal
Since most virtualization hypervisors use iPXE as the primary firmware for PXE booting, the above configuration will directly work without TFTP and PXELinux involved. This is known to work with libvirt, oVirt and RHEV. If the hypervisor is capable of replacing PXE firmware, it will work too (e.g. VMWare is documented at http://ipxe.org/howto/vmware). The workflow is simplified in this case:
153 10 Lukas Zapletal
154
* VM is turned on
155 11 Lukas Zapletal
* iPXE gets network credentials from DHCP again
156 10 Lukas Zapletal
* iPXE gets HTTP address from DHCP
157 1 Alexander Chuzhoy
* iPXE chainloads the iPXE template from Foreman
158
* iPXE loads kernel and init RAM disk of the installer
159 11 Lukas Zapletal
160 12 Lukas Zapletal
To configure this, make sure your hypervisor is using iPXE, configure iPXE template for your host(s) and DHCP server to return valid URL:
161
162
h3. Foreman setup - iPXE template
163
164
Associate iPXE template which ships with Foreman which is named 'Kickstart default iPXE' or 'Preseed default iPXE'. The contents is the same as in the workflows above. If there was a host associated with PXELinux templates, you may need to exit and re-enter Build state for the TFTP configuration to be redeployed. Recent versions of Foreman do this automatically on template save.
165
166
h3. DHCP setup
167
168
Similarly to UNDI configuration, this will lead to an endless loop of chainbooting iPXE firmware. To break this loop, configure DHCP server to hand over correct URL to iPXE to continue booting. In the /etc/dhcp/dhcpd.conf file change the "filename" global or subnet configuration as follows:
169
170
<pre><code>
171
if exists user-class and option user-class = "iPXE" {
172 13 Lukas Zapletal
  filename "https://foreman:443/unattended/iPXE";
173 12 Lukas Zapletal
} else {
174
  filename "pxelinux.0";
175
}
176
</code></pre>
177
178
On isolated networks, use Smart Proxy URL instead of Foreman when templates feature is enabled. If there are existing leases on the DHCP server, let them expire and restart the DHCP service (see above).