How to run Fedora 22 cloud images with KVM

I’m going to assume you already have a working KVM host, with virsh and a networking bridge setup. If not this is a great how-to to get KVM and virsh setup:

First, download the KVM cloud image, go to for the latest image link.

# cd /opt/guests/disk
# wget

I keep my images in /opt/guests/disk and isos in /opt/guests/iso/, you may keep them elsewhere.

Its a good idea to make a copy of this image for each VM because the VM will read and write to this image.

# cp Fedora-Cloud-Base-22_Beta-20150415.x86_64.qcow2 myf22.qcow2

The image is only 3GB by default, you probably want to expand the disk, so lets do that now (you can skip this step if you’re OK with 3GB):

# qemu-img create -f qcow2 -o preallocation=metadata f22tmp.qcow2 20G
# virt-resize –expand /dev/sda1 myf22.qcow2 f22tmp.qcow2
# mv f22tmp.qcow2 myf22.qcow2

Now you’ll need to create an iso for cloud-init. cloud-init will setup your ssh user and networking.

First create the user-data and meta-data files for the iso, update the configuration accordingly.

# cat meta-data
instance-id: myfedora22
local-hostname: myfedora22.domain.tld
network-interfaces: |
iface eth0 inet static

# cat user-data
– name: travis
shell: /bin/bash
–   (insert ssh public key here)

Now generate the iso:

# genisoimage -output /opt/guests/iso/myf22.iso -volid cidata -joliet -rock user-data meta-data
# chown qemu:qemu /opt/guests/iso/myf22.iso

And create the VM:

virt-install –name MyF22 \
–ram 2048 \
–disk /opt/guests/disk/myf22.qcow2 \
–vcpus 2 \
–os-variant fedora21 \
–connect qemu:///system \
–network bridge:br0,model=virtio \
–cdrom /opt/guests/iso/myf22.iso \
–boot hd

After the VM boots you can press ^] to exit the console.

Now you can log into the VM:

ssh travis@

Now the only issue is that on reboot, the cloud-init iso won’t be mounted and your networking settings won’t be provided to the guest. You will need to launch virsh and edit the XML description for the vm and add the source manually.

# virsh

virsh # edit MyF22

Find the disk section that describes the cdrom , it will look like this:

<disk type=’block’ device=’cdrom’>
<driver name=’qemu’ type=’raw’/>
<target dev=’hda’ bus=’ide’/>
<address type=’drive’ controller=’0′ bus=’0′ target=’0′ unit=’0’/>

Change the disk type to “file” and add a source tag with your cloud-init iso as the source:

<disk type=’file‘ device=’cdrom’>
<driver name=’qemu’ type=’raw’/>
  <source file=’/opt/guests/iso/myf22.iso’/>
<target dev=’hda’ bus=’ide’/>
<address type=’drive’ controller=’0′ bus=’0′ target=’0′ unit=’0’/>

This information was gathered from the following sources:

1 comment
  1. Ian said:

    You can avoid the need to change the cdrom definition after creating the VM if you use –import instead of –cdrom as the ‘installation method’, and provide the CDROM as a second disk instead:

    virt-install –name MyF22 \
    –ram 2048 \
    –disk /opt/guests/disk/myf22.qcow2 \
    –disk /opt/guests/iso/myf22.iso,device=cdrom \
    –vcpus 2 \
    –os-variant fedora21 \
    –connect qemu:///system \
    –network bridge:br0,model=virtio \
    –import \
    –boot hd

    The –import option is designed for using an existing disk image, rather than running an OS installer, and that fits the use case here quite well. It is described in the man page:

    Skip the OS installation process, and build a guest around an existing disk image. The device used for booting is the first device specified via “–disk” or

    This also seems to cause virt-install to not complain that the installation has not yet completed when you exit it. Now, on reboot of the domain, it still has access to the CDROM disk image, and can get its network information correctly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: