Create a QCOW2 image for Fedora 22 Atomic

This tutorial shows how to create a QCOW2 image that can directly imported via virt-install to test out Fedora 22 Atomic starting from a custom OStree repo.

To create the image, we are going to use both rpm-ostree and rpm-ostree-toolbox. Ensure they are installed as well as Docker, libvirtd and Vagrant-libvirt.

The first phase consists in generating the OStree repo that is going to be used by the image. We can use directly the files from the fedora-atomic project as:


git clone --branch=f22 https://git.fedorahosted.org/git/fedora-atomic.git
ostree --repo=repo init --mode=archive-z2
rpm-ostree-toolbox treecompose -c fedora-atomic/config.ini --ostreerepo repo # Creates a new repo

At the end of this process, we have a new OStree repository which contains the tree of a Fedora 22 Cloud.

The second phase is more tricky and requires some manual customizations. Also it requires Docker, Vagrant-libvirt and libvirtd.

To use the repository that we have created in the first phase, we need to spawn an OStree HTTP daemon that will serve the files.

We do it by running:


cd repo
ostree -d trivial-httpd -p - # It will print the TCP port it is listening on

As the comment above says, OStree will print to stout the port where the server is listening on. Take note of it as we will need it later.

We are almost ready to create the QCOW2 image. For the unattended installation of the operating system, we need the fedora-cloud-atomic.ks file from the spin-kickstarts.git project.


git clone --branch=f22 https://git.fedorahosted.org/git/spin-kickstarts.git
cp spin-kickstarts/fedora-cloud-atomic.ks .

At this point, modify ./fedora-cloud-atomic.ks to point to our OStree repository.

This is how I modified the file to point to the OStree repo accessible at http://192.168.125.225:37375/. Use the correct settings for your machine, and the port used to serve the OStree repository that we noted before.


--- spin-kickstarts/fedora-cloud-atomic.ks	2015-04-17 15:41:17.124330230 +0200
+++ fedora-cloud-atomic.ks	2015-04-20 00:52:12.990728422 +0200
@@ -33,14 +33,14 @@
 logvol / --size=3000 --fstype="xfs" --name=root --vgname=atomicos
 
 # Equivalent of %include fedora-repo.ks
-ostreesetup --nogpg --osname=fedora-atomic --remote=fedora-atomic --url=http://kojipkgs.fedoraproject.org/mash/atomic/22/ --ref=fedora-atomic/f22/x86_64/docker-host
+ostreesetup --nogpg --osname=fedora-atomic --remote=fedora-atomic --url=http://192.168.125.225:37375/ --ref=fedora-atomic/f22/x86_64/docker-host
 
 reboot
 
 %post --erroronfail
 # See https://github.com/projectatomic/rpm-ostree/issues/42
 ostree remote delete fedora-atomic
-ostree remote add --set=gpg-verify=false fedora-atomic 'http://dl.fedoraproject.org/pub/fedora/linux/atomic/22/'
+ostree remote add --set=gpg-verify=false fedora-atomic 'http://192.168.125.225:37375/'
 
 # older versions of livecd-tools do not follow "rootpw --lock" line above
 # https://bugzilla.redhat.com/show_bug.cgi?id=964299

Now we are really ready to generate the image:


rpm-ostree-toolbox imagefactory -c fedora-atomic/config.ini -o output -i kvm -k fedora-cloud-atomic.ks --tdl fedora-atomic/fedora-atomic-22.tdl --ostreerepo repo

If everything goes as expected, the image file will be under output/images.


ls output/images
fedora-atomic-f22.qcow2.gz  SHA256SUMS

At this point it can be imported through virt-install as (atomic0cidata.iso is a CD iso which contains the cloud-init initialization data):


gunzip output/images/fedora-atomic-f22.qcow2.gz
virt-install --name f22-cloud --ram 2048 --import --disk path=output/images/fedora-atomic-f22.qcow2 --os-type=fedora-21 --graphics spice --disk path=atomic0cidata.iso,device=cdrom

This command will create a new VM named f22-cloud with 2G of RAM using the QCOW2 image we’ve generated.

Have fun!

Tweet about this on TwitterShare on Google+Share on FacebookEmail this to someoneShare on LinkedInShare on Reddit

2 thoughts on “Create a QCOW2 image for Fedora 22 Atomic”

  1. hello, i am trying to build Fedora Atomic 22 by referring above steps.
    >> rpm-ostree-toolbox imagefactory -c fedora-atomic/config.ini -o output -i kvm -k fedora-cloud-atomic.ks –tdl fedora-atomic/fedora-atomic-22.tdl –ostreerepo repo
    ERROR OUTPUT:-
    xception encountered in _build_image_from_template thread
    Could not reach destination to fetch boot media
    .
    .
    raise oz.OzException.OzException(“Could not reach destination to fetch boot media”)
    OzException: Could not reach destination to fetch boot media
    Failed image status: FAILED
    ——————————————————————————————————
    i did all necessary changes, into .ks file. when i am manually trying to connect ostree repo, i am able to do so..

    [root@localhost temp]# wget https://192.168.122.60:54781–2015-10-01 14:13:15– https://192.168.122.60:54781/
    Connecting to 192.168.122.60:54781… connected.

    i put same https://192.168.122.60:54781 in .ks file.

    will please help me to resolve this

    1. there is not boot.iso anymore under /pub/fedora/linux/releases/22/Everything/x86_64/os/.

      Could you change this file in fedora-atomic? It solved the problem for me.


      diff --git a/fedora-atomic-22.tdl b/fedora-atomic-22.tdl
      index 819183f..4092723 100644
      --- a/fedora-atomic-22.tdl
      +++ b/fedora-atomic-22.tdl
      @@ -5,7 +5,7 @@
      22
      x86_64

      - https://dl.fedoraproject.org/pub/fedora/linux/releases/22/Everything/x86_64/os/
      + http://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/x86_64/os/

      ewwwwwww

Leave a Reply

Your email address will not be published. Required fields are marked *