If you did not migrate your account yet, visit https://idp-portal-info.suse.com/
SDB:KIWI Cookbook Virtual Image
Going virtual - our third recipe
The previous examples focused on the creation of iso images you could test and run with qemuor as a LiveCD/DVD.
Kiwi supports the creation of Xen and VMware virtual images. Virtualbox another popular virtualization environment supports the VMware virtual disk format, thus you may use Virtualbox or VMware player to execute the VMware image created in this example.
Once again we will use an openSUSE 11.1 example as the starting point.
- First Steps
As a general best practice it is recommended to work in different directories for different image types.
Create working directories
Copy the example used as the starting point
- Second Step
Change the config.xml file to meet your needs, i.e. change the description, add packages etc.
The config.xml for VMware
Taking a look at the config.xml file (/tmp/myvmguest/config.xml) you will notice significant changes to the type tag in the preferences element. Compared to the previous use of the type tag new attributes are used and the value changed for the VMware image generation. Lets take a closer look at the type tag.
The type tag
The config.xml file for our previous example, the LiveCD example, contained a type element definition as follows:
<type primary="true" boot="isoboot/suse-11.1" flags="unified">iso</type>
The value "iso" specifies that this type declaration is used to create images of type iso, i.e. a LiveCD. Kiwi supports the creation of multiple image types from the same image description, i.e. multiple "type" declarations are supported. Therefore we need a way to indicate which type should be generated by default (no --type argument on the command line). This is accomplished with the primary attribute. Setting primary="true" sets the image type as the default.
Please refer to the KIWI Image System Cookbook in /usr/share/doc/packages/kiwi/kiwi.pdf, installed with the kiwi-doc package or the online version found here for details about the "boot" and "flags" attributes.
The type element definition for the VMware image is shown below:
<type primary="true" filesystem="ext3" boot="vmxboot/suse-11.1" format="vmdk">vmx</type>
The value "vmx" specifies that this type declaration is used to create images usable by the VMware tool chain. As in the LiveCD example, the "primary" attribute is set to "true" to make this image the default image. The image will use the VMware disk format vmdk with an ext3 file system.
If we wanted to use the same image description to create multiple images we can add multiple "type" elements to the config.xml file, as mentioned above. The following example shows how this is specified in the config.xml file.
<preferences> <type primary="true" filesystem="ext3" boot="vmxboot/suse-11.1" format="vmdk" >vmx</type> <type boot="isoboot/suse-11.1" flags="unified" >iso</type> </preferences>
In this example the VMware image is considered the default. Therefore it is necessary to add the --type iso command line argument to the invocation of kiwi to trigger the creation of a LiveCD image. Note that specifying a type on the command line that is not configured in the XML will trigger an error.
In the config.xml file for the VMware image to be created by Kiwi we need to specify attributes for the VM itself. The VM attributes are specified with the vmwareconfig element.
VMware requires a so called guest conﬁguration. This configuration specifies the virtual hardware profile, i.e. hard drive, memory etc. The VMware hardware profile can be specified in the vmwareconfig element of the Kiwi config.xml file. The kiwi toolchain will process the section and generate the appropriate encoding for VMware, following is a short example.
<vmwareconfig memory="512"> <vmwaredisk controller="ide" id="0"/> </vmwareconfig>
Based on this information Kiwi will create a VMware guest image with 512 MB of RAM and an IDE disk controller interface with the disk-id 0.
Building a VMware image with Kiwi allows you to include packages on a conditional basis, i.e. packages that will only be included when you build a VMware image. Other image types also support this functionality. For details see the KIWI Image System Cookbook in /usr/share/doc/packages/kiwi/kiwi.pdf, installed with the kiwi-doc package, or the online version found here. Including conditional packages in accomplished with the "type" attribute on the "packages" element as shown below.
<packages type="vmware"> </packages>
- Building the VMware image
With the changes completed we can now proceed to build our VMware virtual machine using Kiwi. The following command also uses the automatically mounted DVD as the installation source. As previously noted the target directory is expected to be empty, otherwise the kiwi tool chain will error out.
- Image preparation
- # kiwi --prepare /tmp/myvmguest --root /tmp/myvm-root --set-repo /media/SU1110.001
- Image creation
- # kiwi --create /tmp/myvm-root -d /tmp/myvm-image
Once the Kiwi image creation process is complete you can use the resulting .vmx and .vmdk files in /tmp/myvm-image to run the VM in VMware player or Virtualbox.
In addition Kiwi creates a file with the .raw extension (located in the same directory). This file has the same structure a physical hard drive would have and can be used with Qemu, it is not needed when using the image with VMware player or Virtualbox.
You may use the .raw file with the qemu command as follows:
Had we chosen Xen as the preferred virtual environment for this example Kiwi would have generated the Xen specific virtual disk image file in addition to the .raw file.