Openstack Liberty Lab Part 8: Add VM Image

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

In this part of the series, we will complete the complete process of adding an image for inserting a virtual machine on the Openstack Cloud platorm. I will show you how to use virt-install tool to install an operating system from an ISO image and export it. I think you have covered all other parts of the series. They include:

Openstack Liberty Lab Part 1: Setting up the network and all prerequisites

Openstack Liberty Lab Part 2: Install the Openstack software package

Openstack Liberty Lab Part 3: Configure Keystone Identity Service

Openstack Liberty Lab Part 4: Configure Glance Image Service

Openstack Liberty Lab Part V: Configure Nova Computing Service

Openstack Liberty Lab Part VI: Configure Neutron Network Services

Openstack Liberty Lab Part 7: Configure Horizon Dashboard Service

Let us delve into the process of creating and uploading virtual machine images. We will use virt-install command for all installations. In order to use the virt-install command, you should have installed all the KVM packages in Part 1 and Part 2 of the series. If you have not done so, you can do it here: For Ubuntu/Debian systems, do the following:

[[email protected] ~]# apt-get -y install virtinst qemu-kvm bridge-utils libvirt-bin

For RHEL / CentOS 7:

For Arch Linux, please read:

Completely install KVM, QEMU and Virt Manager on Arch Linux and Manjaro

Now you can create a virtual machine image at a glance. I will demonstrate the installation of Ubuntu 14.04 server and CentOS 7.2 server image files.

CentOS

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

Download CentOS

[[email protected] ~]# cp /home/josepy/Kvm images/CentOS-7-x86_64-Minimal-1503-01.iso /var/lib/libvirt/images/
  1. Create a qcow2 image disk:
[[email protected] ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/centos-server.qcow2 10G
  1. Use virt-install command to install CentOS 7.
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 ([email protected]) (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 the ISO image obtained online during installation. Just point the –location option to its url.

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

[[email protected] ~]# 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
  • Start the installation 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 the os variant using the following methods:
[[email protected] ~]# osinfo-query os

Network options can be specified as follows:

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

The next step is to add the created image to it, the steps are:

  1. Prepare the VM for export.
  • Start the guest computer, and then:

For CentOS

[[email protected] ~]# vi /etc/rc.d/rc.local

plus:

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

In order for the instance to access the metadata service, the default zeroconf routing must be disabled:

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

For Ubuntu: install cloud-init

# apt-get install cloud-init

# dpkg-reconfigure cloud-init

  • Shut down the instance, and then clear the MAC address details:
[[email protected] ~]# virt-sysprep -d centos-server
[[email protected] ~] # virt-sysprep -d ubuntu-server

Now, we can upload the virtual machine image to the Image service.

  1. Ensure that the network boot protocol is set to DHCP on the virtual machine.
  2. Uncomment or delete the UUID set in the network configuration file.

Add the CentOS server image:

[[email protected] ~]# 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 the Ubuntu server image:

[[email protected] ~]# 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 the list of added images:
[[email protected] images]# glance image-list 
+---------------------------------------------+--------------------+
| ID | Name |
+----------------------------------------------+-------------------+
| 4dd5dfac-da3b-49bf-80bd-989642421eb0 | Ubuntu-server |
| 0742131d-ac17-48ba-abf5-160a435085ba | Centos-server |
+--------------------------------------+----------------------------+ 

You are ready to start the virtual machine from the image you just added. We will start the virtual machine in the next part of this series. You can use the glance image-delete command to delete a panoramic image, as shown below:

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

You can use the command glance image-delete to delete the current image:

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

Check again:

[[email protected] ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[[email protected] ~]#

Previous:

Openstack Liberty Lab Part 7: Configure Horizon Dashboard Service

Next article:

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

Sidebar