Debian Codegraph @

doc/source/example_use_cases/legacy_netboot_root_filesystem.rst

raw
1 .. _build_legacy_pxe:
2
3 Build PXE Root Filesystem Image for the legacy netboot infrastructure
4 ======================================================================
5
6 .. _PXE: https://en.wikipedia.org/wiki/Preboot_Execution_Environment
7 .. _TFTP: https://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
8 .. _NBD: https://en.wikipedia.org/wiki/Network_block_device
9 .. _AoE: https://en.wikipedia.org/wiki/ATA_over_Ethernet
10
11
12 .. sidebar:: Abstract
13
14 This page explains how to build a filesystem image for use with
15 {kiwi}'s PXE boot infrastructure. It contains:
16
17 * how to build a PXE filesystem image
18 * how to set up the PXE filesystem image on the PXE server
19 * how to run it with QEMU
20
21 `PXE`_ is a network boot protocol that is shipped with most BIOS
22 implementations. The protocol sends a DHCP request to get an IP
23 address. When an IP address is assigned, it uses the `TFTP`_ protocol
24 to download a Kernel and boot instructions. Contrary to other images
25 built with {kiwi}, a PXE image consists of separate boot, kernel, and root
26 filesystem images, since these images need to be made available in
27 different locations on the PXE boot server.
28
29 A root filesystem image that can be deployed via {kiwi}'s PXE
30 netboot infrastructure represents the system's rootfs in a Linux
31 filesystem. A user could loop mount the image and access the
32 contents of the root filesystem. The image does not contain
33 any information about the system disk, its partitions, or the
34 bootloader setup. All of this information is provided by a
35 client configuration file on the PXE server, which controls
36 how the root filesystem image should be deployed.
37
38 Many different deployment strategies are possible, e.g., root over
39 `NBD`_ (network block device), `AoE`_ (ATA over Ethernet), or
40 NFS for diskless and diskful clients. This particular
41 example shows how to build an overlayfs-based union system based
42 on openSUSE Leap for a diskless client that receives the squashfs-
43 compressed root filesystem image in a ramdisk overlayed via
44 overlayfs and writes new data into another ramdisk on the same
45 system. As a diskless client, a QEMU virtual machine is used.
46
47 .. compound:: **Things to know before**
48
49 * To use the image, all image parts need to be copied to the PXE boot
50 server. If you have not set up such a server, refer to
51 :ref:`network-boot-server` for instructions.
52
53 * The following example assumes you will create the PXE image
54 on the PXE boot server itself (if not, use `scp` to copy the files
55 to the remote host).
56
57 * To let QEMU connect to the network, we recommend setting up
58 a network bridge on the host system and letting QEMU connect
59 to it via a custom :file:`/etc/qemu-ifup`. For details, see
60 https://en.wikibooks.org/wiki/QEMU/Networking
61
62 * The PXE root filesystem image approach is considered a
63 legacy setup. The required netboot initrd code will be maintained
64 outside of the {kiwi} appliance builder code base. If possible,
65 we recommend switching to the OEM disk image deployment via
66 PXE.
67
68 1. Build the image with {kiwi}:
69
70 .. code:: bash
71
72 $ sudo kiwi-ng --profile Flat system build \
73 --description kiwi/build-tests/{exc_description_pxe} \
74 --set-repo {exc_repo_tumbleweed} \
75 --target-dir /tmp/mypxe-result
76
77 2. Change into the build directory:
78
79 .. code:: bash
80
81 $ cd /tmp/mypxe-result
82
83 3. Copy the initrd and the kernel to :file:`/srv/tftpboot/boot`:
84
85 .. code:: bash
86
87 $ cp *.initrd /srv/tftpboot/boot/initrd
88 $ cp *.kernel /srv/tftpboot/boot/linux
89
90 4. Copy the system image and its SHA256 sum to :file:`/srv/tftpboot/image`:
91
92 .. code:: bash
93
94 $ cp {exc_image_base_name_pxe}.x86_64-{exc_image_version_pxe} /srv/tftpboot/image
95 $ cp {exc_image_base_name_pxe}.x86_64-{exc_image_version_pxe}.sha256 /srv/tftpboot/image
96
97 5. Adjust the PXE configuration file.
98 The configuration file controls which kernel and initrd is
99 loaded and which kernel parameters are set. A template has been installed
100 at :file:`/srv/tftpboot/pxelinux.cfg/default` from the ``kiwi-pxeboot``
101 package. The minimal configuration required to boot the example image
102 looks like the following:
103
104 .. code:: bash
105
106 DEFAULT KIWI-Boot
107
108 LABEL KIWI-Boot
109 kernel boot/linux
110 append initrd=boot/initrd
111 IPAPPEND 2
112
113 6. Create the image client configuration file:
114
115 .. code:: bash
116
117 $ vi /srv/tftpboot/KIWI/config.default
118
119 IMAGE=/dev/ram1;{exc_image_base_name_pxe}.x86_64;{exc_image_version_pxe};192.168.100.2;4096
120 UNIONFS_CONFIG=/dev/ram2,/dev/ram1,overlay
121
122 All PXE boot-based deployment methods are controlled by a client
123 configuration file. The above configuration tells the client where
124 to find the image and how to activate it. In this case, the image
125 will be deployed into a ramdisk (`ram1`) and overlay mounted such
126 that all write operations will land in another ramdisk (`ram2`).
127 {kiwi} supports a variety of different deployment strategies based
128 on the rootfs image created beforehand. For details, refer
129 to :ref:`pxe_legacy_client_config`.
130
131 7. Connect the client to the network and boot. This can also be done
132 in a virtualized environment using QEMU as follows:
133
134 .. code:: bash
135
136 $ sudo qemu -boot n -m 4096
137
138 .. _pxe_legacy_client_config:
139
140 PXE Client Setup Configuration
141 ------------------------------
142
143 All PXE boot-based deployment methods are controlled by configuration files
144 located in :file:`/srv/tftpboot/KIWI` on the PXE server. Such a configuration
145 file can either be client-specific (config.MAC_ADDRESS, for example
146 config.00.AB.F3.11.73.C8), or generic (config.default).
147
148 In an environment
149 with heterogeneous clients, this allows for a default configuration
150 suitable for the majority of clients, configurations suitable
151 for a group of clients (for example, machines with similar or identical
152 hardware), and individual configurations for selected machines.
153
154 The configuration file contains data about the image and about
155 configuration, synchronization, and partition parameters.
156 The configuration file has the following general format:
157
158 .. code:: bash
159
160 IMAGE="device;name;version;srvip;bsize;compressed,...,"
161
162 DISK="device"
163 PART="size;id;Mount,...,size;id;Mount"
164 RAID="raid-level;device1;device2;..."
165
166 AOEROOT=ro-device[,rw-device]
167 NBDROOT="ip-address;export-name;device;swap-export-name;swap-device;write-export-name;write-device"
168 NFSROOT="ip-address;path"
169
170 UNIONFS_CONFIG="rw-partition,compressed-partition,overlay"
171
172 CONF="src;dest;srvip;bsize;[hash],...,src;dest;srvip;bsize;[hash]"
173
174 KIWI_BOOT_TIMEOUT="seconds"
175 KIWI_KERNEL_OPTIONS="opt1 opt2 ..."
176
177 REBOOT_IMAGE=1
178 RELOAD_CONFIG=1
179 RELOAD_IMAGE=1
180
181 .. note:: Quoting the Values
182
183 The configuration file is sourced by Bash, so the same quoting
184 rules as for Bash apply.
185
186 Not all configuration options need to be specified. It depends on the
187 setup of the client which configuration values are required. The
188 following is a collection of client setup examples that cover all
189 supported PXE client configurations.
190
191 Setup Client with Remote Root
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193
194 To serve the image from a remote location and redirect all
195 write operations to a tmpfs, the following setup is required:
196
197 .. code:: bash
198
199 # When using AoE, see vblade toolchain for image export
200
201 AOEROOT=/dev/etherd/e0.1
202 UNIONFS_CONFIG=tmpfs,aoe,overlay
203
204 # When using NFS, see exports manual page for image export
205
206 NFSROOT="192.168.100.2;/srv/tftpboot/image/root"
207 UNIONFS_CONFIG=tmpfs,nfs,overlay
208
209 # When using NBD, see nbd-server manual page for image export
210
211 NBDROOT=192.168.100.2;root_export;/dev/nbd0
212 UNIONFS_CONFIG=tmpfs,nbd,overlay
213
214 The above setup shows the most common use case where the image built
215 with {kiwi} is populated over the network using either AoE, NBD, or NFS
216 in combination with overlayfs, which redirects all write operations
217 to be local to the client. In any case, a setup of either AoE, NBD, or
218 NFS on the image server is required beforehand.
219
220 Setup Client with System on Local Disk
221 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
222
223 To deploy the image on a local disk, the following setup
224 is required:
225
226 .. note::
227
228 In the referenced `{exc_description_pxe}` XML description, the `pxe`
229 type must be changed as follows, and the image needs to be
230 rebuilt:
231
232 .. code:: xml
233
234 <type image="pxe" filesystem="ext3" boot="{exc_netboot}"/>
235
236 .. code:: bash
237
238 IMAGE="/dev/sda2;{exc_image_base_name_pxe}.x86_64;{exc_image_version_pxe};192.168.100.2;4096"
239 DISK="/dev/sda"
240 PART="5;S;X,X;L;/"
241
242 The setup above will create a partition table on `sda` with a 5MB swap
243 partition (no mountpoint), and the rest of the disk will be a Linux(L)
244 partition with `/` as its mountpoint. The (`X`) in the `PART` setup specifies
245 a placeholder to indicate the default behavior.
246
247 Setup Client with System on Local MD RAID Disk
248 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249
250 To deploy the image on a local disk with a prior software RAID
251 configuration, the following setup is required:
252
253 .. note::
254
255 In the referenced `{exc_description_pxe}` XML description, the `pxe`
256 type must be changed as follows, and the image needs to be
257 rebuilt:
258
259 .. code:: xml
260
261 <type image="pxe" filesystem="ext3" boot="{exc_netboot}"/>
262
263 .. code:: bash
264
265 RAID="1;/dev/sda;/dev/sdb"
266 IMAGE="/dev/md1;{exc_image_base_name_pxe}.x86_64;{exc_image_version_pxe};192.168.100.2;4096"
267 PART="5;S;x,x;L;/"
268
269 The first parameter of the RAID line is the RAID level. So far, only raid1
270 (mirroring) is supported. The second and third parameters specify the
271 raid disk devices that make up the array. If a `RAID` line is present,
272 all partitions in `PART` will be created as RAID partitions. The first
273 RAID is named `md0`, the second one `md1`, and so on. It is required to
274 specify the correct RAID partition in the `IMAGE` line according to the
275 `PART` setup. In this case, `md0` is reserved for the SWAP space, and `md1`
276 is reserved for the system.
277
278 Setup Loading of Custom Configuration File(s)
279 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
280
281 To load, for example, a custom :file:`/etc/hosts` file on the client,
282 the following setup is required:
283
284 .. code:: bash
285
286 CONF="hosts;/etc/hosts;192.168.1.2;4096;ffffffff"
287
288 On boot of the client, {kiwi}'s boot code will fetch the :file:`hosts` file
289 from the root of the server (192.168.1.2) with 4k blocksize and deploy
290 it as :file:`/etc/hosts` on the client. The protocol is tftp by default
291 but can be changed via the `kiwiservertype` kernel command-line option.
292 For details, see :ref:`custom-download-server`.
293
294 Setup Client to Force Reload Image
295 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296
297 To force the reload of the system image even if the image on
298 the disk is up-to-date, the following setup is required:
299
300 .. code:: bash
301
302 RELOAD_IMAGE=1
303
304 The option only applies to configurations with a `DISK`/`PART` setup.
305
306 Setup Client to Force Reload Configuration Files
307 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308
309 To force the reload of all configuration files specified in
310 CONF, the following setup is required:
311
312 .. code:: bash
313
314 RELOAD_CONFIG=1
315
316 By default, only configuration files that have changed according to
317 their checksum value will be reloaded. With the above setup, all files
318 will be reloaded from the PXE server. The option only applies to
319 configurations with a `DISK`/`PART` setup.
320
321 Setup Client for Reboot After Deployment
322 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323
324 To reboot the system after the initial deployment process is
325 done, the following setup is required:
326
327 .. code:: bash
328
329 REBOOT_IMAGE=1
330
331 Setup custom kernel boot options
332 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333
334 To deactivate the kernel mode setting on the local
335 boot of the client, the following setup is required:
336
337 .. code:: bash
338
339 KIWI_KERNEL_OPTIONS="nomodeset"
340
341 .. note::
342
343 This does not influence the kernel options passed to the client
344 if it boots from the network. To set up those, the PXE
345 configuration on the PXE server needs to be changed.
346
347 Setup a Custom Boot Timeout
348 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
349
350 To set up a 10-second custom timeout for the local boot of the client,
351 the following setup is required.
352
353 .. code:: bash
354
355 KIWI_BOOT_TIMEOUT="10"
356
357 .. note::
358
359 This does not influence the boot timeout if the client boots from
360 the network.
361
362 .. _custom-download-server:
363
364 Setup a Different Download Protocol and Server
365 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366
367 By default, all downloads controlled by the {kiwi} linuxrc code are
368 performed by an atftp call using the TFTP protocol. With PXE, the download
369 protocol is fixed, and thus you cannot change the way the kernel and
370 the boot image (:file:`initrd`) are downloaded. As soon as Linux takes over, the
371 download protocols http, https, and ftp are also supported. {kiwi} uses
372 the `curl` program to support the additional protocols.
373
374 To select one of the additional download protocols, the following
375 kernel parameters need to be specified:
376
377 .. code:: bash
378
379 kiwiserver=192.168.1.1 kiwiservertype=ftp
380
381 To set up these parameters, edit the file
382 :file:`/srv/tftpboot/pxelinux.cfg/default` on your PXE boot server and change
383 the append line accordingly.
384
385 .. note::
386
387 Once configured, all downloads except for kernel and initrd are
388 now controlled by the given server and protocol. You need to make
389 sure that this server provides the same directory and file structure
390 as initially provided by the `kiwi-pxeboot` package.