Creating a CentOS VM image for OpenStack

When you install OpenStack, you will get a very simple Linux VM image (Cirros) to test your installation. This works fine for testing purposes, but you will probably want to add some VM images for CentOS or Ubuntu. Although there are predefined VM images available, they may not suit your needs. This guide will create a CentOS VM image with a tool called oz-install.

The oz-install tool automatically installs operating systems into files that represent disk images. The input is an XML file representing the operating system and packages to be installed. The one we will use for CentOS 6.5 is as follows (centos65.tdl):

   <description>CentOS 6.5 x86_64 template</description>
      <install type='url'>

We also use a kickstart file to describe the installation process. It contains settings about the timezone, keyboard, users, etc. The one we will use is as follows (centos65.ks):

key --skip
keyboard us
lang en_US.UTF-8
network --device eth0 --bootproto dhcp
rootpw changeme
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Europe/Amsterdam
bootloader --location=mbr --append="console=tty0 console=ttyS0,115200"
zerombr yes
clearpart --all
part /boot --fstype ext4 --size=200
part swap --size=512
part / --fstype ext4 --size=1024 --grow
repo --name=epel --baseurl=


rpm -Uvh
rm -f /etc/udev/rules.d/70-persistent-net.rules
sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's,UUID=[^[:blank:]]* / ,/dev/vda3               / ,' /etc/fstab
sed -i 's,UUID=[^[:blank:]]* /boot,/dev/vda1               /boot,' /etc/fstab
sed -i 's,UUID=[^[:blank:]]* swap,/dev/vda2               swap,' /etc/fstab
rm -f /root/anaconda-ks.cfg
rm -f /root/install.log
rm -f /root/install.log.syslog
find /var/log -type f -delete

Install CentOS 6.5 (a lower version may also work) and use the following command to install oz-install and its dependencies:

yum -y install kvm libvirt oz qemu-kvm

Now we can tell oz-install to use both files and create the actual VM image:

oz-install -p -u -d1 -a centos65.ks centos65.tdl

When this step is finished, we can convert the resulting image file to the QCOW2 format:

qemu-img convert /var/lib/libvirt/images/centos65_x86_64.dsk -O qcow2 /root/centos65_x86_64.qcow2

The last step is actually uploading the VM image to OpenStack (can be done through the command line or the GUI) and start using it.


5 thoughts on “Creating a CentOS VM image for OpenStack

  1. Permalink  ⋅ Reply


    February 7, 2014 at 12:52pm

    Thats perfect! Short and needed information

  2. Permalink  ⋅ Reply


    April 2, 2014 at 11:26am

    Bedankt werkt perfect!
    Wat ik me nog wel af vroeg… Ik wil een vm image maken van een CENTOS minimal install.
    Nu loop ik als ik een iso gebruik steeds vast in het laatste stukje. Er lijk een scherm of popup te zijn tijdens de installatie waar hij niet door heen komt..

    Nu heb ik geprobeerd de iso te mounten, maar het lukt me niet om deze goed aan te roepen in de *tdl file.


  3. Permalink  ⋅ Reply


    September 5, 2014 at 5:59am


    Today i was creating image for centos but getting failed like this :

    “Fetching the original media
    Attempting to get the lock for /var/lib/oz/isos/CentOS-65x86_64-url.iso
    Got the lock, doing the download
    Fetching the original install media from
    Cleaning up after install
    Traceback (most recent call last):
    File “/usr/bin/oz-install”, line 159, in
    customize or generate_icicle)
    File “/usr/lib/python2.6/site-packages/oz/”, line 659, in generate_install_media
    File “/usr/lib/python2.6/site-packages/oz/”, line 1772, in _iso_generate_install_media
    self._get_original_iso(url, force_download)
    File “/usr/lib/python2.6/site-packages/oz/”, line 1404, in _get_original_iso
    self._get_original_media(isourl, self.orig_iso, force_download)
    File “/usr/lib/python2.6/site-packages/oz/”, line 911, in _get_original_media
    oz.ozutil.http_download_file(url, fd, True, self.log)
    File “/usr/lib/python2.6/site-packages/oz/”, line 831, in http_download_file
    pycurl.error: (6, ‘name lookup timed out’) ”

    The command that i use is :

    # oz-install -p -u -d1 -a centos65.ks centos65.tdl -d3

    Is there any solution for this ?


  4. Permalink  ⋅ Reply

    Jeff Silverman

    October 1, 2014 at 12:55am

    The command to import the qcow file into an image is

    glance image-create –name Centos_6.5 –is-public=true –container-format=bare –disk-format=qcow2 –file /root/centos65_x86_64.qcow2

Leave a Reply

Your email will not be published. Name and Email fields are required.