You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this part of the series we’re going to work through complete process of Adding images used to soin virtual machines on Openstack Cloud platorm.I will show you how to use virt-install tool to install OS from an ISO image and export it.
I assume you’ve already covered all other Parts of the series. They include:

Openstack Liberty Lab Part One: Setup Networking and all Prerequisites

Openstack Liberty Lab Part Two: Install Openstack Packages

Openstack Liberty Lab Part Three: Configuring Keystone identity service

Openstack Liberty Lab Part Four: Configuring Glance Image Service

Openstack Liberty Lab Part Five: Configure Nova Compute Service

Openstack Liberty Lab Part Six: Configure Neutron Network Service

Openstack Liberty Lab Part Seven: Configure Horizon Dashboard Service

Let’s dive into process of creating and uploading virtual machine images.We’ll do all installations using virt-install command.
In order to use virt-install command, you should have install all KVM packages from Part 1 and 2 of the series. If you didn’t do it, you can do it here:
For Ubuntu/Debian systems do:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20apt-get%20-y%20install%20virtinst%20qemu-kvm%20bridge-utils%20libvirt-bin%0A”/]

For RHEL/CentOS 7:

 

For Arch Linux read:

Complete Installation of KVM,QEMU and Virt Manager on Arch Linux and Manjaro

You can now create virtual Machine image for glance. I will demonstrate installation of Ubuntu 14.04 server and CentOS 7.2 server image files.

CentOS

First copy CentOS 7 iso image to /var/lib/libvirt/images/. You can download it from official CentOS page:

Download CentOS

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20cp%20%2Fhome%2Fjosepy%2FKvm%20images%2FCentOS-7-x86_64-Minimal-1503-01.iso%20%2Fvar%2Flib%2Flibvirt%2Fimages%2F%0A”/]

  1. Create qcow2 image disk:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20qemu-img%20create%20-f%20qcow2%20%2Fvar%2Flib%2Flibvirt%2Fimages%2Fcentos-server.qcow2%2010G%0A”/]

  1. Installing CentOS 7 using virt-install command.

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”virt-install%20%0A–name%20centos-server%20%0A–ram%201024%20%0A–disk%20path%3D%2Fvar%2Flib%2Flibvirt%2Fimages%2Fcentos-server.qcow2%20%0A–vcpus%201%20%0A–os-type%20linux%20%0A–os-variant%20rhel7%20%0A–graphics%20none%20%0A–console%20pty%2Ctarget_type%3Dserial%20%0A–location%20%2Fvar%2Flib%2Flibvirt%2Fimages%2FCentOS-7-x86_64-Minimal-1503-01.iso%20%0A–extra-args%20’console%3DttyS0%2C115200n8%20serial'”/]

Sample output:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”Starting%20install…%0ARetrieving%20file%20.treeinfo…%20%7C%201.1%20kB%2000%3A00%3A00%20%0ARetrieving%20file%20vmlinuz…%20%7C%204.8%20MB%2000%3A00%3A00%20%0ARetrieving%20file%20initrd.img…%20%7C%2034%20MB%2000%3A00%3A00%20%0ACreating%20domain…%20%7C%200%20B%2000%3A00%3A05%20%0AConnected%20to%20domain%20centos-server%0AEscape%20character%20is%20%5E%5D%0A%5B%200.000000%5D%20Initializing%20cgroup%20subsys%20cpuset%0A%5B%200.000000%5D%20Initializing%20cgroup%20subsys%20cpu%0A%5B%200.000000%5D%20Initializing%20cgroup%20subsys%20cpuacct%0A%5B%200.000000%5D%20Linux%20version%203.10.0-229.el7.x86_64%20(builder%40kbuilder.dev.centos.org)%20(gcc%20version%204.8.2%2020140120%20(Red%20Hat%204.8.2-16)%20(GCC)%20)%20%231%20SMP%20Fri%20Mar%206%2011%3A36%3A42%20UTC%202015%0A%5B%200.000000%5D%20Command%20line%3A%20console%3DttyS0%2C115200n8%20serial%0A%5B%200.000000%5D%20e820%3A%20BIOS-provided%20physical%20RAM%20map%3A%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200×0000000000000000-0x000000000009fbff%5D%20usable%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200x000000000009fc00-0x000000000009ffff%5D%20reserved%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200x00000000000f0000-0x00000000000fffff%5D%20reserved%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200×0000000000100000-0x000000003ffd8fff%5D%20usable%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200x000000003ffd9000-0x000000003fffffff%5D%20reserved%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200x00000000feffc000-0x00000000feffffff%5D%20reserved%0A%5B%200.000000%5D%20BIOS-e820%3A%20%5Bmem%200x00000000fffc0000-0x00000000ffffffff%5D%20reserved%0A%5B%200.000000%5D%20NX%20(Execute%20Disable)%20protection%3A%20active%0A%5B%200.000000%5D%20SMBIOS%202.8%20present.%0A%5B%200.000000%5D%20Hypervisor%20detected%3A%20KVM%0A%5B%200.000000%5D%20No%20AGP%20bridge%20found%0A%5B%200.000000%5D%20e820%3A%20last_pfn%20%3D%200x3ffd9%20max_arch_pfn%20%3D%200×400000000%0A%5B%200.000000%5D%20×86%20PAT%20enabled%3A%20cpu%200%2C%20old%200×7040600070406%2C%20new%200×7010600070106%0A%5B%200.000000%5D%20found%20SMP%20MP-table%20at%20%5Bmem%200x000f6b40-0x000f6b4f%5D%20mapped%20at%20%5Bffff8800000f6b40%5D%0A%5B%200.000000%5D%20init_memory_mapping%3A%20%5Bmem%200×00000000-0x000fffff%5D%0A%5B%200.000000%5D%20init_memory_mapping%3A%20%5Bmem%200x3da00000-0x3dbfffff%5D%0A%5B%200.000000%5D%20init_memory_mapping%3A%20%5Bmem%200x3c000000-0x3d9fffff%5D%0A%5B%200.000000%5D%20init_memory_mapping%3A%20%5Bmem%200×00100000-0x3bffffff%5D%0A%5B%200.000000%5D%20init_memory_mapping%3A%20%5Bmem%200x3dc00000-0x3ffd8fff%5D%0A%5B%200.000000%5D%20RAMDISK%3A%20%5Bmem%200x3ddb9000-0x3ffcffff%5D%0A%5B%200.000000%5D%20ACPI%3A%20RSDP%2000000000000f6960%2000014%20(v00%20BOCHS%20)%0A%5B%200.000000%5D%20ACPI%3A%20RSDT%20000000003ffe1647%2000030%20(v01%20BOCHS%20BXPCRSDT%2000000001%20BXPC%2000000001)%0A%5B%200.000000%5D%20ACPI%3A%20FACP%20000000003ffe0bda%2000074%20(v01%20BOCHS%20BXPCFACP%2000000001%20BXPC%2000000001)%0A%5B%200.000000%5D%20ACPI%3A%20DSDT%20000000003ffe0040%2000B9A%20(v01%20BOCHS%20BXPCDSDT%2000000001%20BXPC%2000000001)%0A%5B%200.000000%5D%20ACPI%3A%20FACS%20000000003ffe0000%2000040%0A%5B%200.000000%5D%20ACPI%3A%20SSDT%20000000003ffe0c4e%2000981%20(v01%20BOCHS%20BXPCSSDT%2000000001%20BXPC%2000000001)%0A%5B%200.000000%5D%20ACPI%3A%20APIC%20000000003ffe15cf%2000078%20(v01%20BOCHS%20BXPCAPIC%2000000001%20BXPC%2000000001)%0A%5B%200.000000%5D%20No%20NUMA%20configuration%20found%0A%5B%200.000000%5D%20Faking%20a%20node%20at%20%5Bmem%200×0000000000000000-0x000000003ffd8fff%5D%0A%5B%200.000000%5D%20Initmem%20setup%20node%200%20%5Bmem%200×00000000-0x3ffd8fff%5D%0A%5B%200.000000%5D%20NODE_DATA%20%5Bmem%200x3dd92000-0x3ddb8fff%5D%0A%5B%200.000000%5D%20kvm-clock%3A%20Using%20msrs%204b564d01%20and%204b564d00%0AStart%20installation%20by%20changing%20settings%20to%20your%20liking.%20They%20are%20numbered%201-9%0AStarting%20installer%2C%20one%20moment…%0Aanaconda%2019.31.123-1%20for%20CentOS%207%20started.%0A*%20installation%20log%20files%20are%20stored%20in%20%2Ftmp%20during%20the%20installation%0A*%20shell%20is%20available%20on%20TTY2%0A*%20when%20reporting%20a%20bug%20add%20logs%20from%20%2Ftmp%20as%20separate%20text%2Fplain%20attachments%0A16%3A54%3A56%20Not%20asking%20for%20VNC%20because%20we%20don’t%20have%20a%20network%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0AInstallation%201)%20%5Bx%5D%20Language%20settings%202)%20%5B!%5D%20Timezone%20settings%0A%0A%0A(English%20(United%20States))%20(Timezone%20is%20not%20set.)%0A3)%20%5B!%5D%20Software%20selection%204)%20%5B!%5D%20Installation%20source%0A%0A(Processing…)%20(Processing…)%0A5)%20%5Bx%5D%20Network%20settings%206)%20%5B!%5D%20Install%20Destination%0A%0A(Not%20connected)%20(No%20disks%20selected)%0A7)%20%5Bx%5D%20Kdump%208)%20%5B!%5D%20Create%20user%0A%0A(Kdump%20is%20enabled)%20(No%20user%20will%20be%20created)%0A9)%20%5B!%5D%20Set%20root%20password%0A%0A(Password%20is%20not%20set.)%0APlease%20make%20your%20choice%20from%20above%20%5B’q’%20to%20quit%20%7C%20’b’%20to%20begin%20installation%20%7C%0A’r’%20to%20refresh%5D%3A”/]

 

You can use ISO image obtained online while doing installation. Just point –location option to its url .

  1. Installing Ubuntu/Debian using virt-install command.

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20qemu-img%20create%20-f%20qcow2%20%2Fvar%2Flib%2Flibvirt%2Fimages%2Fubuntu-server.qcow2%2010G%0AFormatting%20’%2Fvar%2Flib%2Flibvirt%2Fimages%2Fubuntu-server.qcow2’%2C%20fmt%3Dqcow2%20size%3D10737418240%20encryption%3Doff%20cluster_size%3D65536%20lazy_refcounts%3Doff%20refcount_bits%3D16%0A”/]

  • Launch install process:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”virt-install%20%0A–name%20ubuntu-server%20%0A–ram%201024%20%0A–disk%20path%3D%2Fvar%2Flib%2Flibvirt%2Fimages%2Fubuntu-server.qcow2%20%0A–vcpus%201%20%0A–os-type%20linux%20%0A–os-variant%20ubuntu14.04%20%0A–graphics%20spice%20%0A–hvm%20%0A–console%20pty%2Ctarget_type%3Dserial%20%0A–cdrom%3D%2Fvar%2Flib%2Flibvirt%2Fimages%2Fubuntu-14.04.3-server-amd64.iso”/]

  • You can Check os variant using:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20osinfo-query%20os%0A”/]

Network option can be specified as below:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”–network%3Dbridge%3Abr100%0A–network%3Dnetwork%3Adefault”/]

Next step is adding images created to , steps are:

  1. Make VM ready for export.
  • Start guest machine, then:

For CentOS

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20vi%20%2Fetc%2Frc.d%2Frc.local%0A”/]

Add:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”if%20%5B%20!%20-d%20%2Froot%2F.ssh%20%5D%3B%20then%0Amkdir%20-p%20%2Froot%2F.ssh%0Achmod%20700%20%2Froot%2F.ssh%0Afi%20%23%20Fetch%20public%20key%20using%20HTTP%0AATTEMPTS%3D30%0AFAILED%3D0%0Awhile%20%5B%20!%20-f%20%2Froot%2F.ssh%2Fauthorized_keys%20%5D%3B%20do%0Acurl%20-f%20http%3A%2F%2F169.254.169.254%2Flatest%2Fmeta-data%2Fpublic-keys%2F0%2Fopenssh-key%20%0A%0A%0A%3E%20%2Ftmp%2Fmetadata-key%202%3E%2Fdev%2Fnull%0Aif%20%5B%20%24%3F%20-eq%200%20%5D%3B%20then%0A%0Acat%20%2Ftmp%2Fmetadata-key%20%3E%3E%20%2Froot%2F.ssh%2Fauthorized_keys%0Achmod%200600%20%2Froot%2F.ssh%2Fauthorized_keys%0Arestorecon%20%2Froot%2F.ssh%2Fauthorized_keys%0Arm%20-f%20%2Ftmp%2Fmetadata-key%0Aecho%20%22Successfully%20retrieved%20public%20key%20from%20instance%20metadata%22%0Aecho%20%22*****************%22%0Aecho%20%22AUTHORIZED%20KEYS%22%0Aecho%20%22*****************%22%0Acat%20%2Froot%2F.ssh%2Fauthorized_keys%0Aecho%20%22*****************%22%0Afi%0Adone%0A”/]

For an instance to access the metadata service, you must disable the default zeroconf route:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%23%20echo%20%22NOZEROCONF%3Dyes%22%20%3E%3E%20%2Fetc%2Fsysconfig%2Fnetwork%0A”/]

For Ubuntu:
Install cloud-init

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%23%20apt-get%20install%20cloud-init%0A%0A%23%20dpkg-reconfigure%20cloud-init”/]

 

  • Shutdown the instance, then clean up MAC address details:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20virt-sysprep%20-d%20centos-server%0A%5Broot%40controller%20~%5D%20%23%20virt-sysprep%20-d%20ubuntu-server”/]

We can now upload virtual machines images to the Image service.

  1. Make sure network boot protocol is set to DHCP on th virtual machine.
  2. Uncomment or remove UUID set in network configuration file.

Add CentOS server image:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20glance%20image-create%20–name%20%22Centos-server%22%20–file%20%2Fvar%2Flib%2Flibvirt%2Fimages%2Fcentos-server.qcow2%20–disk-format%20qcow2%20–container-format%20bare%20–visibility%20public%0A%2B——————%2B————————————–%2B%0A%7C%20Property%20%7C%20Value%20%7C%0A%2B——————%2B————————————–%2B%0A%7C%20checksum%20%7C%203198fc821f3202425dc8254469eacad4%20%7C%0A%7C%20container_format%20%7C%20bare%20%7C%0A%7C%20created_at%20%7C%202016-03-29T20%3A29%3A08Z%20%7C%0A%7C%20disk_form%20t%20%7C%20qcow2%20%7C%0A%7C%20id%20%7C%200742131d-ac17-48ba-abf5-160a435085ba%20%7C%0A%7C%20min_disk%20%7C%200%20%7C%0A%7C%20min_ram%20%7C%200%20%7C%0A%7C%20name%20%7C%20Centos-server%20%7C%0A%7C%20owner%20%7C%20abc5d2a310ad46fba0b2a311a187088b%20%7C%0A%7C%20protected%20%7C%20False%20%7C%0A%7C%20size%20%7C%204071686144%20%7C%0A%7C%20status%20%7C%20active%20%7C%0A%7C%20tags%20%7C%20%5B%5D%20%7C%0A%7C%20updated_at%20%7C%202016-03-29T20%3A31%3A40Z%20%7C%0A%7C%20virtual_size%20%7C%20None%20%7C%0A%7C%20visibility%20%7C%20public%20%7C%0A%2B——————%2B————————————–%2B%0A”/]

Add Ubuntu Server image:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20glance%20image-create%20–name%20%22Ubuntu-server%22%20–file%20%2Fvar%2Flib%2Flibvirt%2Fimages%2Fubuntu-server.qcow2%20–disk-format%20qcow2%20–container-format%20bare%20–visibility%20public%0A%2B——————%2B————————————–%2B%0A%7C%20Property%20%7C%20Value%20%7C%0A%2B——————%2B————————————–%2B%0A%7C%20checksum%20%7C%203198fc821f3202425dc8254469eacad4%20%7C%0A%7C%20container_format%20%7C%20bare%20%7C%0A%7C%20created_at%20%7C%202016-03-29T20%3A29%3A08Z%20%7C%0A%7C%20disk_form%20t%20%7C%20qcow2%20%7C%0A%7C%20id%20%7C%200742131d-ac17-48ba-abf5-160a435085ba%20%7C%0A%7C%20min_disk%20%7C%200%20%7C%0A%7C%20min_ram%20%7C%200%20%7C%0A%7C%20name%20%7C%20Ubuntu-server%20%7C%0A%7C%20owner%20%7C%20abc5d2a310ad46fba0b2a311a187088b%20%7C%0A%7C%20protected%20%7C%20False%20%7C%0A%7C%20size%20%7C%204071686144%20%7C%0A%7C%20status%20%7C%20active%20%7C%0A%7C%20tags%20%7C%20%5B%5D%20%7C%0A%7C%20updated_at%20%7C%202016-03-29T20%3A31%3A40Z%20%7C%0A%7C%20virtual_size%20%7C%20None%20%7C%0A%7C%20visibility%20%7C%20public%20%7C%0A%2B——————%2B————————————–%2B”/]

  • Check list of images added:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20images%5D%23%20glance%20image-list%20%0A%2B———————————————%2B——————–%2B%0A%7C%20ID%20%7C%20Name%20%7C%0A%2B———————————————-%2B——————-%2B%0A%7C%204dd5dfac-da3b-49bf-80bd-989642421eb0%20%7C%20Ubuntu-server%20%7C%0A%7C%200742131d-ac17-48ba-abf5-160a435085ba%20%7C%20Centos-server%20%7C%0A%2B————————————–%2B—————————-%2B%C2%A0″/]

You’re ready to launch a virtual machine off the images you just added.We’ll do so in the next part of the series.
Glance images can be deleted using glance image-delete command as shown below:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%C2%A0%5Broot%40controller%20~%5D%23%20glance%20image-list%0A%2B—————————————————————–%2B————————%2B%0A%7C%20ID%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7C%20Name%C2%A0%C2%A0%C2%A0%C2%A0%20%C2%A0%20%C2%A0%20%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7C%0A%2B—————————————————————–%2B————————-%2B%0A%7C%204dd5dfac-da3b-49bf-80bd-989642421eb0%20%7C%20Centos-server%20%7C%0A%7C%200742131d-ac17-48ba-abf5-160a435085ba%7C%20Ubuntu-server%20%7C%0A%2B——————————————————————%2B————————–%2B”/]

You can delete present image using the command glance image-delete:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20glance%20image-delete%204dd5dfac-da3b-49bf-80bd-989642421eb0%20%0A%5Broot%40controller%20~%5D%23%20glance%20image-delete%200742131d-ac17-48ba-abf5-160a435085ba”/]

Check again:

[pastacode lang=”bash” message=”” highlight=”” provider=”manual” manual=”%5Broot%40controller%20~%5D%23%20glance%20image-list%0A%2B—-%2B——%2B%0A%7C%20ID%20%7C%20Name%20%7C%0A%2B—-%2B——%2B%0A%2B—-%2B——%2B%0A%5Broot%40controller%20~%5D%23″/]

PREVIOUS ARTICLE:

Openstack Liberty Lab Part Seven: Configure Horizon Dashboard ServiceĀ 

NEXT ARTICLE:

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF