Debian Codegraph @

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