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:

[root@controller ~]# apt-get -y install virtinst qemu-kvm bridge-utils libvirt-bin

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

[root@controller ~]# cp /home/josepy/Kvm images/CentOS-7-x86_64-Minimal-1503-01.iso /var/lib/libvirt/images/
  1. Create qcow2 image disk:
[root@controller ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/centos-server.qcow2 10G
  1. Installing CentOS 7 using virt-install command.
virt-install 
--name centos-server 
--ram 1024 
--disk path=/var/lib/libvirt/images/centos-server.qcow2 
--vcpus 1 
--os-type linux 
--os-variant rhel7 
--graphics none 
--console pty,target_type=serial 
--location /var/lib/libvirt/images/CentOS-7-x86_64-Minimal-1503-01.iso 
--extra-args 'console=ttyS0,115200n8 serial'

Sample output:

Starting install...
Retrieving file .treeinfo... | 1.1 kB 00:00:00 
Retrieving file vmlinuz... | 4.8 MB 00:00:00 
Retrieving file initrd.img... | 34 MB 00:00:00 
Creating domain... | 0 B 00:00:05 
Connected to domain centos-server
Escape character is ^]
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.10.0-229.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Fri Mar 6 11:36:42 UTC 2015
[ 0.000000] Command line: console=ttyS0,115200n8 serial
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003ffd8fff] usable
[ 0.000000] BIOS-e820: [mem 0x000000003ffd9000-0x000000003fffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] Hypervisor detected: KVM
[ 0.000000] No AGP bridge found
[ 0.000000] e820: last_pfn = 0x3ffd9 max_arch_pfn = 0x400000000
[ 0.000000] x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
[ 0.000000] found SMP MP-table at [mem 0x000f6b40-0x000f6b4f] mapped at [ffff8800000f6b40]
[ 0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
[ 0.000000] init_memory_mapping: [mem 0x3da00000-0x3dbfffff]
[ 0.000000] init_memory_mapping: [mem 0x3c000000-0x3d9fffff]
[ 0.000000] init_memory_mapping: [mem 0x00100000-0x3bffffff]
[ 0.000000] init_memory_mapping: [mem 0x3dc00000-0x3ffd8fff]
[ 0.000000] RAMDISK: [mem 0x3ddb9000-0x3ffcffff]
[ 0.000000] ACPI: RSDP 00000000000f6960 00014 (v00 BOCHS )
[ 0.000000] ACPI: RSDT 000000003ffe1647 00030 (v01 BOCHS BXPCRSDT 00000001 BXPC 00000001)
[ 0.000000] ACPI: FACP 000000003ffe0bda 00074 (v01 BOCHS BXPCFACP 00000001 BXPC 00000001)
[ 0.000000] ACPI: DSDT 000000003ffe0040 00B9A (v01 BOCHS BXPCDSDT 00000001 BXPC 00000001)
[ 0.000000] ACPI: FACS 000000003ffe0000 00040
[ 0.000000] ACPI: SSDT 000000003ffe0c4e 00981 (v01 BOCHS BXPCSSDT 00000001 BXPC 00000001)
[ 0.000000] ACPI: APIC 000000003ffe15cf 00078 (v01 BOCHS BXPCAPIC 00000001 BXPC 00000001)
[ 0.000000] No NUMA configuration found
[ 0.000000] Faking a node at [mem 0x0000000000000000-0x000000003ffd8fff]
[ 0.000000] Initmem setup node 0 [mem 0x00000000-0x3ffd8fff]
[ 0.000000] NODE_DATA [mem 0x3dd92000-0x3ddb8fff]
[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
Start installation by changing settings to your liking. They are numbered 1-9
Starting installer, one moment...
anaconda 19.31.123-1 for CentOS 7 started.
* installation log files are stored in /tmp during the installation
* shell is available on TTY2
* when reporting a bug add logs from /tmp as separate text/plain attachments
16:54:56 Not asking for VNC because we don't have a network
================================================================================
================================================================================
Installation 1) [x] Language settings 2) [!] Timezone settings


(English (United States)) (Timezone is not set.)
3) [!] Software selection 4) [!] Installation source

(Processing...) (Processing...)
5) [x] Network settings 6) [!] Install Destination

(Not connected) (No disks selected)
7) [x] Kdump 8) [!] Create user

(Kdump is enabled) (No user will be created)
9) [!] Set root password

(Password is not set.)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]:

 

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.

[root@controller ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu-server.qcow2 10G
Formatting '/var/lib/libvirt/images/ubuntu-server.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
  • Launch install process:
virt-install 
--name ubuntu-server 
--ram 1024 
--disk path=/var/lib/libvirt/images/ubuntu-server.qcow2 
--vcpus 1 
--os-type linux 
--os-variant ubuntu14.04 
--graphics spice 
--hvm 
--console pty,target_type=serial 
--cdrom=/var/lib/libvirt/images/ubuntu-14.04.3-server-amd64.iso
  • You can Check os variant using:
[root@controller ~]# osinfo-query os

Network option can be specified as below:

--network=bridge:br100
--network=network:default

Next step is adding images created to , steps are:

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

For CentOS

[root@controller ~]# vi /etc/rc.d/rc.local

Add:

if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi # Fetch public key using HTTP
ATTEMPTS=30
FAILED=0
while [ ! -f /root/.ssh/authorized_keys ]; do
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key 


> /tmp/metadata-key 2>/dev/null
if [ $? -eq 0 ]; then

cat /tmp/metadata-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/metadata-key
echo "Successfully retrieved public key from instance metadata"
echo "*****************"
echo "AUTHORIZED KEYS"
echo "*****************"
cat /root/.ssh/authorized_keys
echo "*****************"
fi
done

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

# echo "NOZEROCONF=yes" >> /etc/sysconfig/network

For Ubuntu:
Install cloud-init

# apt-get install cloud-init

# dpkg-reconfigure cloud-init

 

  • Shutdown the instance, then clean up MAC address details:
[root@controller ~]# virt-sysprep -d centos-server
[root@controller ~] # virt-sysprep -d ubuntu-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:

[root@controller ~]# glance image-create --name "Centos-server" --file /var/lib/libvirt/images/centos-server.qcow2 --disk-format qcow2 --container-format bare --visibility public
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 3198fc821f3202425dc8254469eacad4 |
| container_format | bare |
| created_at | 2016-03-29T20:29:08Z |
| disk_form t | qcow2 |
| id | 0742131d-ac17-48ba-abf5-160a435085ba |
| min_disk | 0 |
| min_ram | 0 |
| name | Centos-server |
| owner | abc5d2a310ad46fba0b2a311a187088b |
| protected | False |
| size | 4071686144 |
| status | active |
| tags | [] |
| updated_at | 2016-03-29T20:31:40Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------+

Add Ubuntu Server image:

[root@controller ~]# glance image-create --name "Ubuntu-server" --file /var/lib/libvirt/images/ubuntu-server.qcow2 --disk-format qcow2 --container-format bare --visibility public
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 3198fc821f3202425dc8254469eacad4 |
| container_format | bare |
| created_at | 2016-03-29T20:29:08Z |
| disk_form t | qcow2 |
| id | 0742131d-ac17-48ba-abf5-160a435085ba |
| min_disk | 0 |
| min_ram | 0 |
| name | Ubuntu-server |
| owner | abc5d2a310ad46fba0b2a311a187088b |
| protected | False |
| size | 4071686144 |
| status | active |
| tags | [] |
| updated_at | 2016-03-29T20:31:40Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------+
  • Check list of images added:
[root@controller images]# glance image-list 
+---------------------------------------------+--------------------+
| ID | Name |
+----------------------------------------------+-------------------+
| 4dd5dfac-da3b-49bf-80bd-989642421eb0 | Ubuntu-server |
| 0742131d-ac17-48ba-abf5-160a435085ba | Centos-server |
+--------------------------------------+----------------------------+ 

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:

 [root@controller ~]# glance image-list
+-----------------------------------------------------------------+------------------------+
| ID                                                               | Name               |
+-----------------------------------------------------------------+-------------------------+
| 4dd5dfac-da3b-49bf-80bd-989642421eb0 | Centos-server |
| 0742131d-ac17-48ba-abf5-160a435085ba| Ubuntu-server |
+------------------------------------------------------------------+--------------------------+

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

[root@controller ~]# glance image-delete 4dd5dfac-da3b-49bf-80bd-989642421eb0 
[root@controller ~]# glance image-delete 0742131d-ac17-48ba-abf5-160a435085ba

Check again:

[root@controller ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[root@controller ~]#

PREVIOUS ARTICLE:

Openstack Liberty Lab Part Seven: Configure Horizon Dashboard Service 

NEXT ARTICLE: