Why build a qcow2 Fedora Rawhide image for a VM?
Because Fedora Rawhide has nightly builds and is not guaranteed to be stable, you may not want to upgrade your stable version of Fedora to Rawhide. Still, you may want to test Rawhide, or download certain packages to it without actually installing it to your own computer.
While you could use a container, the main benefits in using a VM are:
- You can run multiple applications at once.
- Your VM will be more secure than a container.
- You aren’t limited to one version of the OS, meaning you can have a variety of OSes in the VM.
So this article discusses how to build your own VM and install Rawhide to it. However, if you’d like to generate an image for a container instead, refer to this previous article about building Fedora Rawhide images with Imagefactory.
Currently, Fedora 25 is about to be released. Therefore, Rawhide corresponds to what will eventually be Fedora 26. Many references in this article point to F26 as a result. You should be able to adjust these references for later releases.
To install the necessary packages, run this command:
sudo dnf install imagefactory libvirt virt-manager
Create a kickstart file
To build the image from scratch, you need a Fedora 26 Cloud kickstart file. This file defines what will be installed in the image.
Create a cloud-init ISO file
To login to your image, you must create a cloud-init ISO file in advance. Refer to instructions for creating this file on the Project Atomic site. If the URL in the first step of that page does not work, try the Fedora 24 qcow2 image located here.
Then proceed with the following steps, making sure to to replace any occurrences of F26 with F24. (The process is the same.)
Create your own template file
The template file describes some image settings. It declares the root user’s password, and tells the installer where to find the latest Fedora 26 repo. Below is an example template, which you can create with the name f26-cloud.tdl.
<template> <name>My-F26-Cloud-Image</name> <os> <name>Fedora</name> <version>26</version> <arch>x86_64</arch> <install type='url'> <url>https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Everything/x86_64</url> </install> <rootpw>redhat</rootpw> </os> </template>
Modify the Oz configuration
Next, modify the Oz configuration file
/etc/oz/oz.cfg. Comment out the following line:
image_type = raw
Add this line below it:
image_type = qcow2
This tells Imagefactory, which is built on Oz, to create the base image as a qcow2 image.
Generate the qcow2 image
Now you’re ready to generate the qcow2 image. In this example, the kickstart file is named f26-cloud.ks. The template file is named f26-cloud.tdl.
sudo imagefactory --debug base_image --file-parameter install_script f26-cloud.ks f26-cloud.tdl --parameter offline_icicle true
In this example, debugging is set on, but this isn’t required. Once the process is done, Imagefactory produces output similar to this:
============ Final Image Details ============ UUID: 4ebde351-e81b-427f-96b7-5acd5680013d Type: base_image Image filename: /var/lib/imagefactory/storage/4ebde351-e81b-427f-96b7-5acd5680013d.body Image build completed SUCCESSFULLY!
Here, 4ebde351-e81b-427f-96b7-5acd5680013d.body is the qcow2 image, even though the extension says .body. To confirm, run this command using your image’s file name:
You should see output showing your image is qcow2 formatted:
4ebde351-e81b-427f-96b7-5acd5680013d.body: QEMU QCOW Image (v2), 10737418240 bytes
For consistency, you may want to rename this file so the extension matches the file type.
Now that you’ve created the image, it’s time to use virt-manager to run it. Before you can do that, however, you must move the image file to /var/lib/libvirt/images. This lets you run it in virt-manager. This command renames and moves the file:
sudo mv -Z /var/lib/imagefactory/storage/4ebde351-e81b-427f-96b7-5acd5680013d.body /var/lib/libvirt/images/my-f26-cloud-image.qcow2
You should also place your ISO file in the same folder. This way you can use it for other images you create later. Use the mv -Z command so the ISO file gets the proper default SELinux label.
Run your new qcow2 image
Now it’s time to run virt-manager:
Click File > New Virtual Machine to spin up the VM creator. Choose Import existing disk image, then click Forward.
On this page, browse for the qcow2 image you just created. Then set the OS type as Linux. For Version, scroll to the bottom of the dropdown list. Select the last option to automatically set the version to Fedora. Now hit Forward.
The default memory and CPU settings will work with the example kickstart file. Accept the default and click Forward once more.
On this page, name the VM something like My-f26-Cloud-image. Before you hit Forward, check the Customize configuration before install box, then click Finish. A new window opens so you can customize the VM.
On the bottom left of this window, click the Add hardware button and select Storage. Check the Select or Create Custom Storage option. To add your cloud-init ISO, click the Manage button and select the ISO you created earlier. Now under Device type, select CDROM and leave the Bus type as IDE. Click Finish, then Begin Installation on the upper left corner. This automatically starts your newly-created VM.
To login, your username is fedora and your password is the one defined in your template file. Enjoy your new VM!