Debian Codegraph @

doc/source/example_use_cases/build_expandable_disk.rst

raw
1 .. _expandable_disk:
2
3 Build an Expandable Disk Image
4 ==============================
5
6 .. sidebar:: Abstract
7
8 This page explains how to build an expandable disk image.
9 It covers the following topics:
10
11 * builds an expandable disk image
12 * deploys an expandable disk image
13 * runs the deployed system
14
15 An expandable disk represents the system disk with the capability to automatically
16 expand the disk and its filesystem to a custom disk geometry. This
17 allows deploying the same disk image on target systems with different
18 hardware setups.
19
20 The following example shows how to build and deploy an expandable disk image
21 based on openSUSE Leap using a QEMU virtual machine as a target
22 system:
23
24 1. Build an image with {kiwi}:
25
26 .. code:: bash
27
28 $ sudo kiwi-ng --type oem system build \
29 --description kiwi/build-tests/{exc_description_disk} \
30 --set-repo {exc_repo_leap} \
31 --target-dir /tmp/myimage
32
33 The resulting image is saved in :file:`/tmp/myimage`.
34
35 * The disk image with the suffix :file:`.raw` is an expandable
36 virtual disk. It can expand itself to a custom disk geometry.
37
38 * The installation image with the suffix :file:`.install.iso` is a
39 hybrid installation system that contains the disk image and is
40 capable of installing this image on any target disk.
41
42 .. _deployment_methods:
43
44 Deployment Methods
45 ------------------
46
47 The goal of an expandable disk image is to provide the virtual
48 disk data for OEM vendors to support easy deployment of the system to
49 physical storage media.
50
51 Basic deployment strategies are as follows:
52
53 1. :ref:`deploy_manually`
54
55 Manually deploy the disk image onto the target disk.
56
57 2. :ref:`deploy_from_iso`
58
59 Boot the installation image and let {kiwi}'s installer
60 deploy the disk image from a CD/DVD or USB stick onto the target disk.
61
62 3. :ref:`deploy_from_network`
63
64 PXE boot the target system and let {kiwi}'s installer
65 deploy the disk image from the network onto the target disk.
66
67 .. _deploy_manually:
68
69 Manual Deployment
70 -----------------
71
72 The manual deployment method can be tested using virtualization software
73 like QEMU and an additional virtual large-size target disk.
74 To do this, follow the steps below.
75
76 1. Create a target disk:
77
78 .. code:: bash
79
80 $ qemu-img create target_disk 20g
81
82 .. note:: Retaining the Disk Geometry
83
84 If the target disk geometry is less than or equal to the geometry of
85 the disk image itself, the disk expansion that is performed on a physical
86 disk install during the boot workflow is skipped, and the
87 original disk geometry stays unchanged.
88
89 2. Dump the disk image on the target disk:
90
91 .. code:: bash
92
93 $ dd if={exc_image_base_name_disk}.x86_64-{exc_image_version}.raw of=target_disk conv=notrunc
94
95 3. Boot the target disk:
96
97 .. code:: bash
98
99 $ sudo qemu -hda target_disk -m 4096 -serial stdio
100
101
102 On the first boot of the `target_disk`, the system is expanded to the
103 configured storage layout. By default, the system root partition
104 and filesystem are resized to the maximum free space available.
105
106 .. _deploy_from_iso:
107
108 CD/DVD Deployment
109 -----------------
110
111 The deployment from a CD/DVD via an installation image can
112 also be tested using virtualization software such as QEMU.
113 To do this, follow the steps below.
114
115 1. Create a target disk:
116
117 Follow the steps above to create a virtual target disk.
118
119 2. Boot the installation image as a CD/DVD with the
120 target disk attached.
121
122 .. code:: bash
123
124 $ sudo qemu -cdrom \
125 {exc_image_base_name_disk}.x86_64-{exc_image_version}.install.iso -hda target_disk \
126 -boot d -m 4096 -serial stdio
127
128 .. note:: USB Stick Deployment
129
130 Like any other ISO image built with {kiwi}, the installation
131 image is also a hybrid image. Thus, it can also be used on a USB stick and
132 serve as installation media, as explained in
133 :ref:`hybrid_iso`.
134
135 .. _deploy_from_network:
136
137 Network Deployment
138 ------------------
139
140 The process of deployment from the network downloads the disk image from a
141 PXE boot server. This requires a PXE network boot server to be set up
142 as described in :ref:`network-boot-server`.
143
144 If the PXE server is running, the following steps show how to test the
145 deployment process over the network using a QEMU virtual machine as
146 a target system:
147
148 1. Create an installation PXE TAR archive along with your
149 disk image by replacing the following configuration in
150 `kiwi/build-tests/{exc_description_disk}/appliance.kiwi`:
151
152 Find the line below:
153
154 .. code:: xml
155
156 <type image="oem" installiso="true"/>
157
158 Modify the line as follows:
159
160 .. code:: xml
161
162 <type image="oem" installpxe="true"/>
163
164
165 2. Rebuild the image, unpack the resulting
166 :file:`{exc_image_base_name_disk}.x86_64-{exc_image_version}.install.tar`
167 file to a temporary directory, and copy the initrd and kernel images to
168 the PXE server.
169
170 a) Unpack the installation tarball:
171
172 .. code:: bash
173
174 mkdir /tmp/pxe && cd /tmp/pxe
175 tar -xf {exc_image_base_name_disk}.x86_64-{exc_image_version}.install.tar
176
177 b) Copy the kernel and initrd used for PXE boot:
178
179 .. code:: bash
180
181 scp pxeboot.{exc_image_base_name_disk}.x86_64-{exc_image_version}.initrd PXE_SERVER_IP:/srv/tftpboot/boot/initrd
182 scp pxeboot.{exc_image_base_name_disk}.x86_64-{exc_image_version}.kernel PXE_SERVER_IP:/srv/tftpboot/boot/linux
183
184 3. Copy the disk image, SHA256 file, system kernel, initrd, and bootoptions to
185 the PXE boot server.
186
187 Activation of the deployed system is done via `kexec` of the kernel
188 and initrd provided here.
189
190 a) Copy the system image and SHA256 checksum:
191
192 .. code:: bash
193
194 scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.xz PXE_SERVER_IP:/srv/tftpboot/image/
195 scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.sha256 PXE_SERVER_IP:/srv/tftpboot/image/
196
197 b) Copy the kernel, initrd, and bootoptions used for booting the system via kexec:
198
199 .. code:: bash
200
201 scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.initrd PXE_SERVER_IP:/srv/tftpboot/image/
202 scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.kernel PXE_SERVER_IP:/srv/tftpboot/image/
203 scp {exc_image_base_name_disk}.x86_64-{exc_image_version}.config.bootoptions PXE_SERVER_IP:/srv/tftpboot/image/
204
205 .. note::
206
207 The `config.bootoptions` file is used with `kexec` to boot the previously
208 dumped image. This file specifies the root of the dumped image, and the
209 file can include other boot options. The file provided with the
210 {kiwi}-built image is connected to the image present in the PXE TAR archive. If
211 other images are deployed, the file must be modified to match the
212 correct root reference.
213
214 .. note::
215
216 If the image is deployed into a ramdisk that is configured
217 by passing `rd.kiwi.ramdisk` as part of the append setup below,
218 it is not required to copy the above-mentioned kernel and initrd
219 file to boot the system because for ramdisk deployments, the
220 currently active kernel and initrd will be used, as kexec cannot
221 be called with a system in memory.
222
223 4. Add/Update the kernel command-line parameters.
224
225 Edit your PXE configuration (for example, :file:`pxelinux.cfg/default`) on
226 the PXE server and add the following parameters to the append line similar to that shown below:
227
228 .. code:: bash
229
230 append initrd=boot/initrd rd.kiwi.install.pxe rd.kiwi.install.image=tftp://192.168.100.16/image/{exc_image_base_name_disk}.x86_64-{exc_image_version}.xz
231
232 The location of the image is specified as a source URI that can point
233 to any location supported by the `curl` command. {kiwi} uses `curl` to fetch
234 the data from this URI. This means that the image, checksum file, system kernel,
235 and initrd can be fetched from any server and do not need to be stored
236 on the `PXE_SERVER`.
237
238 By default, {kiwi} does not use specific `curl` options or flags. But it is
239 possible to specify desired options by adding the
240 `rd.kiwi.install.pxe.curl_options` flag to the kernel command line (`curl`
241 options are passed as comma-separated values), for example:
242
243 .. code:: bash
244
245 rd.kiwi.install.pxe.curl_options=--retry,3,--retry-delay,3,--speed-limit,2048
246
247 The above instructs {kiwi} to run `curl` as follows:
248
249 .. code:: bash
250
251 curl --retry 3 --retry-delay 3 --speed-limit 2048 -f <url>
252
253 This can be particularly useful when the deployment infrastructure requires a
254 specific download configuration. For example, setting more robust retries
255 over an unstable network connection.
256
257 .. note::
258
259 {kiwi} replaces commas with spaces and appends the result to the `curl`
260 command. Keep that in mind, because command-line options that include
261 commas break the command.
262
263 .. note::
264
265 The initrd and Linux Kernel for PXE boot are always loaded via TFTP
266 from the `PXE_SERVER`.
267
268 5. Create a target disk.
269
270 Follow the steps above to create a virtual target disk.
271
272 6. Connect the client to the network and boot QEMU with the target disk
273 attached to the virtual machine:
274
275 .. code:: bash
276
277 $ sudo qemu -boot n -hda target_disk -m 4096
278
279 .. note:: QEMU bridged networking
280
281 To connect QEMU to the network, we recommend setting up
282 a network bridge on the host system and connecting QEMU
283 to it via a custom `/etc/qemu-ifup` configuration. For details, see
284 https://en.wikibooks.org/wiki/QEMU/Networking.
285
286 .. _oem_customize:
287
288 OEM Customization
289 -----------------
290
291 The deployment process of an OEM image can be customized using
292 the `oemconfig` element. This element is a child section of the `type`
293 element, for example:
294
295 .. code:: xml
296
297 <oemconfig>
298 <oem-swapsize>512</oem-swapsize>
299 </oemconfig>
300
301
302 Below is a list of the most commonly used optional `oemconfig` element settings.
303
304 oemconfig.oem-resize
305 Determines if the disk has the capability to expand itself to
306 a new disk geometry or not. By default, this feature is activated.
307 The implementation of the resize capability is done in a dracut
308 module packaged as `dracut-kiwi-oem-repart`. If `oem-resize` is
309 set to `false`, the installation of the corresponding dracut package
310 can be skipped as well.
311
312 oemconfig.oem-boot-title
313 By default, the string `OEM` is used as the boot manager menu
314 entry when KIWI creates the GRUB configuration during deployment.
315 The `oem-boot-title` element allows you to set a custom name for the
316 grub menu entry. This value is represented by the
317 `kiwi_oemtitle` variable in the initrd.
318
319 oemconfig.oem-bootwait
320 Determines if the system waits for user interaction before
321 continuing the boot process after the disk image has been dumped to
322 the designated storage device (the default value is `false`). This value
323 is represented by the `kiwi_oembootwait` variable in the initrd.
324
325 oemconfig.oem-reboot
326 When enabled, the system is rebooted after the disk image has
327 been deployed to the designated storage device (the default value is
328 `false`). This value is represented by the `kiwi_oemreboot`
329 variable in the initrd.
330
331 oemconfig.oem-reboot-interactive
332 When enabled, the system is rebooted after the disk image has
333 been deployed to the designated storage device (the default value is
334 `false`). Before the reboot, a message is displayed, and it must be
335 acknowledged by the user for the system to reboot. This
336 value is represented by the `kiwi_oemrebootinteractive` variable
337 in the initrd.
338
339 oemconfig.oem-silent-boot
340 Determines if the system boots in silent mode after the disk
341 image has been deployed to the designated storage device (the default
342 value is `false`). This value is represented by the
343 `kiwi_oemsilentboot` variable in the initrd.
344
345 oemconfig.oem-shutdown
346 Determines if the system is powered down after the disk image
347 has been deployed to the designated storage device (the default value
348 is `false`). This value is represented by the `kiwi_oemshutdown`
349 variable in the initrd.
350
351 oemconfig.oem-shutdown-interactive
352 Determines if the system is powered down after the disk image
353 has been deployed to the designated storage device (the default value
354 is `false`). Before the shutdown, a message is displayed, and it must be
355 acknowledged by the user for the system to power off.
356 This value is represented by the `kiwi_oemshutdowninteractive`
357 variable in the initrd.
358
359 oemconfig.oem-swap
360 Determines if a swap partition is created. By default, no
361 swap partition is created. This setting is evaluated by {kiwi} at build
362 time.
363
364 oemconfig.oem-swapname
365 Specifies the name of the swap space. By default, the name is set to
366 `LVSwap`. The default indicates that this setting is only useful in
367 combination with the LVM volume manager. In this case, the swapspace is
368 configured as a volume in the volume group, and every volume requires a name.
369 The name specified in `oemconfig.oem-swapname` here is used as the name of the
370 swap volume.
371
372 oemconfig.oem-swapsize
373 Specifies the size of the swap partition in MB. The value is only used if
374 `oem-swap` is set to `true`. If a swap partition is created while
375 the size of the swap partition is not specified, KIWI uses a default
376 size of 128 MB.
377 This value is represented by the `kiwi_oemswapMB` variable in the initrd.
378
379 oemconfig.oem-systemsize
380 Specifies the MB size the operating system is allowed to occupy on the target
381 disk. The size limit does not include any swap space or recovery partition
382 considerations. In a setup *without* the `systemdisk` element, this value
383 specifies the size of the root partition. In a setup that *includes* the
384 `systemdisk` element when using LVM, this value specifies the size of the LVM
385 partition that contains all specified volumes. This means that the sum of all
386 specified volume sizes plus the sum of the specified freespace for each volume
387 must be smaller than or equal to the size specified with the `oem-systemsize`
388 element. This value is represented by the variable `kiwi_oemrootMB` in the
389 initrd. The specified value can be dynamically overwritten via the
390 `rd.kiwi.install.systemsize` kernel boot option. If `rd.kiwi.install.systemsize`
391 is set to `all`, this will unset the size limit, and the maximum possible
392 size will apply.
393
394 oemconfig.oem-unattended
395 The installation of the image to the target system occurs
396 automatically without requiring user interaction. If multiple
397 possible target devices are discovered, the image is deployed to
398 the first device. This value is represented by the
399 `kiwi_oemunattended` variable in the initrd.
400
401 oemconfig.oem-unattended-id
402 Selects a target disk device for the installation according to the
403 specified device ID. The device ID corresponds to the name of the device for
404 the configured `devicepersistency`. By default, it is the `by-uuid` device
405 name. If no representation exists, for example, for ramdisk devices, the UNIX
406 device node can be used to select one. The given name must be present in the
407 device list detected by KIWI.
408
409 oemconfig.oem-skip-verify
410 Disables the checksum verification process after installing the image on
411 the target disk. The verification process computes the checksum of the image
412 installed on the target. This value is then compared to the initrd-embedded
413 checksum generated at the build time of the image. Depending on the size of the
414 image and machine power, computing the checksum may take time.
415
416 .. _installmedia_customize:
417
418 Installation Media Customization
419 --------------------------------
420
421 The installation media created for OEM network or CD/DVD deployments can
422 be customized with the `installmedia` section. It is a child section of the `type`
423 element, for example:
424
425 .. code:: xml
426
427 <installmedia>
428 <initrd action="omit">
429 <dracut module="network-legacy"/>
430 </initrd>
431 </installmedia>
432
433 The `installmedia` is only available for OEM image types that include the
434 request to create an installation media.
435
436 The `initrd` child element of `installmedia` lists dracut modules. The element's
437 `action` attribute determines whether the dracut module is omitted
438 (`action="omit"`) or added (`action="add"`). Use `action="set"` to use only the
439 listed modules and nothing else (that is, none of the dracut modules included by
440 default).