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:

$ $ $ g o r i s p t t m r - c e o l e s o t n r e - e r e e - - p t b o o r = o a r l n e b c p o h o x = f i t 2 n r 2 i e t e h c t o t - m p m p s o o : d s / e e / = g a - i r c t c . h f f i e e v d d e o o - r r z a a 2 - h a o t s o t m e i d c . / o c r o g n / f g i i g t . / i f n e i d o r a o - s a t t r o e m e i r c e . p g o i t r e p o # C r e a t e s a n e w r e p o

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:

$ $ c o d s t r r e e p e o - d t r i v i a l - h t t p d - p - # I t w i l l p r i n t t h e T C P p o r t i t i s l i s t e n i n g o n

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.

g c i p t s c p l i o n n - e k i c - k b s r t a a n r c t h s = / f f 2 e 2 d o h r t a t - p c s l : u / d g - i a t t . o f m e i d c o . r k a s h o . s t e d . o r g / g i t / s p i n - k i c k s t a r t s . g i t

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
--- 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:

$ r p m - o s t r e e - t o o l b o x i m a g e f a c t o r y - c f e d o r a - a t o m i c / c o n f i g . i n i o u t p u t - i k v m - k f e d o r a - c l o u d - a t o m i c . k s - t d l f e d o r a - a t o m i c / f e d o r a - a t o m i c - 2 2 . t d l o s t r e e r e p o r e p o

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

$ f e l d s o r o a u - t a p t u o t m / i i c m - a f g 2 e 2 s . q c o w 2 . g z S H A 2 5 6 S U M S

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

$ $ g v u i n r z t i - p i n o s u t t a p l u l t / i - m n a a g m e e s / f f 2 e 2 d - o c r l a o - u a d t o m - i r c a - m f 2 2 2 0 . 4 q 8 c o w - 2 i . m g p z o r t - d i s k p a t h = o u t p u t / i m a g e s / f e d o r a - a t o m i c - f 2 2 . q c o w 2 o s - t y p e = f e d o r a - 2 1 - g r a p h i c s s p i c e - d i s k p a t h = a t o m i c 0 c i d a t a . i s o , d e v i c e = c d r o m

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

Have fun!