Debian Codegraph @

doc/source/example_use_cases/build_simple_disk.rst

raw
1 .. _simple_disk:
2
3 Build a Virtual Disk Image
4 ==========================
5
6 .. sidebar:: Abstract
7
8 This page explains how to build a simple disk image.
9 It covers the following topics:
10
11 - defines a simple disk image in the image description
12 - builds a simple disk image
13 - runs it with QEMU
14
15 A simple virtual disk image is a compressed system disk with additional
16 metadata useful for cloud frameworks like Amazon EC2, Google Compute Engine,
17 or Microsoft Azure. It is used as the native disk of a system, and it does
18 not require an additional installation workflow or a complex first-boot setup
19 procedure.
20
21 To enable {kiwi} to build a simple disk image, add a `type` element with
22 `image="oem"` in :file:`config.xml`, where the `oem-resize` option is
23 disabled. An example configuration for a 42-GB large VMDK image with
24 512 MB of RAM, an IDE controller, and a bridged network interface is shown
25 below:
26
27 .. code:: xml
28
29 <image schemaversion="{schema_version}" name="Tumbleweed_appliance">
30 <!-- snip -->
31 <preferences>
32 <type image="oem" filesystem="ext4" format="vmdk">
33 <bootloader name="grub2" timeout="0"/>
34 <size unit="G">42</size>
35 <oemconfig>
36 <oem-resize>false</oem-resize>
37 </oemconfig>
38 <machine memory="512" guestOS="suse" HWversion="4">
39 <vmdisk id="0" controller="ide"/>
40 <vmnic driver="e1000" interface="0" mode="bridged"/>
41 </machine>
42 </type>
43 <!-- additional preferences -->
44 </preferences>
45 <!-- snip -->
46 </image>
47
48 The following attributes of the `type` element deserve attention
49 when building simple disk images:
50
51 - `format`: Specifies the format of the virtual disk. Possible values are
52 `gce`, `ova`, `qcow2`, `vagrant`, `vmdk`, `vdi`, `vhd`, `vhdx`, and
53 `vhd-fixed`.
54
55 In addition, a disk can be wrapped into a container by prefixing the format
56 with `oci:` or `docker:`, for example `format="oci:qcow2"`. The permitted
57 sub-formats are `gce`, `ova`, `qcow2`, `vmdk`, `vdi`, `vhd`, `vhdx`,
58 `vhd-fixed` and `raw`. Note that `vagrant` cannot be used as a sub-format.
59
60 - `formatoptions`: Specifies additional format options passed to
61 :command:`qemu-img`. `formatoptions` is a comma-separated list of
62 format-specific options in a `name=value` format, as expected by
63 :command:`qemu-img`. {kiwi} forwards the settings from the attribute as a
64 parameter to the `-o` option in the :command:`qemu-img` call.
65
66 The `bootloader`, `size`, and `machine` child elements of `type` can be
67 used to customize the virtual machine image. These elements are described in
68 the following sections: :ref:`disk-bootloader`, :ref:`disk-the-size-element`,
69 and :ref:`disk-the-machine-element`.
70
71 Once your image description is finished, you can build the image using the
72 following {kiwi} command:
73
74 .. code:: bash
75
76 $ sudo kiwi-ng system build \
77 --description kiwi/build-tests/{exc_description_disk_simple} \
78 --set-repo {exc_repo_leap} \
79 --target-dir /tmp/myimage
80
81 The resulting :file:`.raw` image is stored in :file:`/tmp/myimage`.
82
83 You can test the image using QEMU:
84
85 .. code:: bash
86
87 $ sudo qemu \
88 -drive file={exc_image_base_name_disk_simple}.x86_64-{exc_image_version}.raw,format=raw,if=virtio \
89 -m 4096
90
91 For further information on how to configure the image to work within a cloud
92 framework, see:
93
94 * :ref:`setup_for_ec2`
95 * :ref:`setup_for_azure`
96 * :ref:`setup_for_gce`
97
98 For information on how to set up a Vagrant system, see :ref:`setup_vagrant`.
99
100 .. _disk-bootloader:
101
102 Setting up the Bootloader in the Image
103 --------------------------------------
104
105 .. code:: xml
106
107 <preferences>
108 <type>
109 <bootloader name="grub2"/>
110 </type>
111 </preferences>
112
113 The `bootloader` element defines which bootloader to use in the
114 image, and the element offers several options for customizing its configuration.
115
116 For details, see :ref:`preferences-type-bootloader`.
117
118 .. _disk-the-size-element:
119
120 Modifying the Size of the Image
121 -------------------------------
122
123 The `size` child element of `type` specifies the size of the resulting
124 disk image. The following example shows an image description where 20 GB are
125 added to the virtual machine image, of which 5 GB are left unpartitioned:
126
127 .. code:: xml
128
129 <preferences>
130 <type image="oem" format="vmdk">
131 <size unit="G" additive="true" unpartitioned="5">20</size>
132 <oemconfig>
133 <oem-resize>false</oem-resize>
134 </oemconfig>
135 </type>
136 </preferences>
137
138 The following optional attributes can be used to further customize the image size:
139
140 - `unit`: Defines the unit used for the provided numerical value. Possible
141 values are `M` for megabytes and `G` for gigabytes. The default unit
142 is megabytes.
143
144 - `additive`: A boolean value that determines whether the provided value is added
145 to the current image size (`additive="true"`) or whether it is the total size
146 (`additive="false"`). The default value is `false`.
147
148 - `unpartitioned`: Specifies the image space in the image that is not
149 partitioned. The attribute uses either the same unit as defined in the attribute
150 `unit` or the default value.
151
152
153 .. _disk-the-machine-element:
154
155 Customizing the Virtual Machine
156 -------------------------------
157
158 The `machine` child element of `type` can be used to customize the virtual
159 machine configuration, including the number of CPUs and the connected network
160 interfaces.
161
162 The following attributes are supported by the `machine` element:
163
164 - `ovftype`: The OVF configuration type. The Open Virtualization Format is a
165 standard for describing virtual appliances and distributing them in an archive
166 called an Open Virtual Appliance (OVA). The standard describes the major
167 components associated with a disk image. The exact specification depends on
168 the product using the format. Supported value is `vmware`.
169
170 - `HWversion`: The virtual machine's hardware version (`vmdk` and `ova`
171 formats only); refer to VMware documentation for further
172 information on the supported values.
173
174 - `arch`: the VM architecture (`vmdk` format only). Valid values are
175 `ix86` (= `i586` and `i686`) and `x86_64`.
176
177 - `xen_loader`: the Xen target loader that is expected to load the guest.
178 Valid values are `hvmloader`, `pygrub`, and `pvgrub`.
179
180 - `guestOS`: The virtual guest OS' identification string for the VM (only
181 applicable for `vmdk` and `ova` formats. Note that the name designation
182 is different for the two formats).
183 Note: For vmware ovftools, guestOS is a VMX GuestOS, but not a VIM GuestOS.
184 For instance, the correct value for Ubuntu 64-bit is "ubuntu-64", but not
185 "ubuntu64Guest". See GUEST_OS_KEY_MAP in guest_os_tables.h at
186 https://github.com/vmware/open-vm-tools for another guestOS values.
187
188 - `min_memory`: The virtual machine's minimum memory in MB (`ova` format
189 only).
190
191 - `max_memory`: The virtual machine's maximum memory in MB (`ova` format
192 only).
193
194 - `min_cpu`: The virtual machine's minimum CPU count (`ova` format only).
195
196 - `max_cpu`: The virtual machine's maximum CPU count (`ova` format only).
197
198 - `memory`: The virtual machine's memory in MB (all formats).
199
200 - `ncpus`: The number of virtual CPUs available to the virtual machine (all
201 formats).
202
203 `machine` also supports additional child elements that are covered in the following
204 subsections.
205
206 Modifying the VM Configuration Directly
207 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
208
209 The `vmconfig-entry` element is used to add entries directly into the
210 virtual machine's configuration file. This is currently only supported for
211 the `vmdk` format, where the provided strings are directly pasted into the
212 :file:`.vmx` file.
213
214 The `vmconfig-entry` element has no attributes and can appear multiple
215 times. The entries are added to the configuration file in the provided
216 order. Note that {kiwi} does not check the entries for correctness.
217
218 The following example adds the two entries `numvcpus = "4"` and
219 `cpuid.coresPerSocket = "2"` into the VM configuration file:
220
221 .. code:: xml
222
223 <preferences>
224 <type image="oem" filesystem="ext4" format="vmdk">
225 <machine memory="512" guestOS="suse" HWversion="4">
226 <vmconfig-entry>numvcpus = "4"</vmconfig-entry>
227 <vmconfig-entry>cpuid.coresPerSocket = "2"</vmconfig-entry>
228 </machine>
229 </type>
230 </preferences>
231
232 Adding Network Interfaces to the VM
233 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234
235 Network interfaces can be explicitly specified for the VM when required via
236 the `vmnic` element. This makes it possible to add another bridged interface or
237 to specify the driver to be used.
238
239 Note that this element is used for the `vmdk` image format only.
240
241 The following example adds a bridged network interface that uses the `e1000`
242 driver:
243
244 .. code:: xml
245
246 <preferences>
247 <type image="oem" filesystem="ext4" format="vmdk">
248 <machine memory="4096" guestOS="suse" HWversion="4">
249 <vmnic driver="e1000" interface="0" mode="bridged"/>
250 </machine>
251 </type>
252 </preferences>
253
254 The `vmnic` element supports the following attributes:
255
256 - `interface`: **Mandatory** interface ID for the VM's network interface.
257
258 - `driver`: An optional driver.
259
260 - `mac`: The MAC address of the specified interface.
261
262 - `mode`: The mode of the interface.
263
264 Note that {kiwi} does **not** verify the values of the
265 attributes; it only inserts them into the appropriate configuration
266 files.
267
268
269 Specifying Disks and Disk Controllers
270 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
271
272 The `vmdisk` element can be used to customize the disk and disk controller for
273 the virtual machine. At most one `vmdisk` element may be specified per `machine`
274 element.
275
276 Note that this element is used for `vmdk` and `ova` image formats only.
277
278 The following example adds a disk with the ID 0 that uses an IDE controller:
279
280 .. code:: xml
281
282 <preferences>
283 <type image="oem" filesystem="ext4" format="vmdk">
284 <machine memory="512" guestOS="suse" HWversion="4">
285 <vmdisk id="0" controller="ide"/>
286 </machine>
287 </type>
288 </preferences>
289
290 Each `vmdisk` element can be further customized using optional
291 attributes:
292
293 - `controller`: The disk controller used for the VM guest (`vmdk` format
294 only). Supported values are `ide`, `buslogic`, `lsilogic`, `lsisas1068`,
295 `legacyESX`, and `pvscsi`.
296
297 - `device`: The disk device to appear in the guest (`xen` format only).
298
299 - `diskmode`: The disk mode (`vmdk` format only). Valid values are
300 `monolithicSparse`, `monolithicFlat`, `twoGbMaxExtentSparse`,
301 `twoGbMaxExtentFlat`, and `streamOptimized` (see also
302 https://vdc-download.vmware.com/vmwb-repository/dcr-public/6335f27c-c6e9-4804-95b0-ea9449958403/c7798a8b-4c73-41d9-84e8-db5453de7b17/doc/vddkDataStruct.5.3.html).
303
304 - `disktype`: The type of the disk handled internally by the VM
305 (`ova` format only). This attribute is currently unused.
306
307 - `id`: The disk ID of the VM disk (`vmdk` format only).
308
309 Adding CD/DVD Drives
310 ^^^^^^^^^^^^^^^^^^^^
311
312 {kiwi} supports adding one IDE or SCSI CD/DVD drive to the virtual
313 machine using the `vmdvd` element for the `vmdk` and `ova` image formats. At most one
314 `vmdvd` element may be specified per `machine` element. The following example
315 adds a single drive with a SCSI controller:
316
317 .. code:: xml
318
319 <preferences>
320 <type image="oem" filesystem="ext4">
321 <machine memory="512" xen_loader="hvmloader">
322 <vmdvd id="0" controller="scsi"/>
323 </machine>
324 </type>
325 </preferences>
326
327 The `vmdvd` element features two **mandatory** attributes:
328
329 - `id`: The CD/DVD ID of the drive.
330
331 - `controller`: The CD/DVD controller used for the VM guest. Valid
332 values are `ide` and `scsi`.