How To Create CentOS 8 KVM Image Template on OpenStack

Posted on 322 views

This guide will discuss how one can create a CentOS 8 KVM image to be used on OpenStack when creating CentOS 8 instances. CentOS 8 was released on September 24th, 2019 and guys are starting to adopt it for running Production workloads. OpenStack is one of the main Virtualization/Cloud environment used by many. companies.

UPDATE:

Official Cloud Image for OpenStack has been released, refer to below guide:

Uploading CentOS 8 Cloud Image to OpenStack Glance

For Vagrant use, check: How To run CentOS 8 VM using Vagrant on KVM / VirtualBox / VMWare / Parallels

Step 1 : Download CentOS 8 ISO image

Download CentOS 8 ISO image to your Workstation.

wget http://isoredirect.centos.org/centos/8/isos/x86_64/CentOS-8-x86_64-1905-dvd1.iso

Upload CentOS 8 ISO image to OpenStack.

openstack image create CentOS8-ISO \
--file CentOS-8-x86_64-1905-dvd1.iso \
--disk-format iso --container-format bare

Confirm image upload from Glance.

 $ openstack image list
+--------------------------------------+---------------+--------+
| ID                                   | Name          | Status |
+--------------------------------------+---------------+--------+
| b8d75f31-fb6b-428b-8b83-f3904b0bd114 | CentOS-7      | active |
| 685d52c7-ad42-45e6-9419-a9971dcad9c1 | CentOS8-ISO   | active |
| fbcf16a0-c7cc-42c1-b836-a39bc34c9666 | Cirros        | active |
| d900bcad-047a-4d01-bcbc-42426bb4315d | CoreOS        | active |
| f0ac705b-ee73-4de8-95f7-4e06569f0f5c | Debian-10     | active |
| 01e6f07b-ca99-439d-9cd0-ab28c2573abf | Fedora-30     | active |
| 1953e548-779c-4fe5-86c1-854d71f35d14 | FreeBSD12     | active |
| 7bd462ad-cc11-4d89-8b85-9aab0cfe114b | Ubuntu-18     | active |
| 86e42aae-d959-4b79-b9a4-b899d85ba303 | fed31         | active |
| 3a56d733-de76-490a-9dac-1419219b5803 | manageiq      | active |
| 47b5b6ed-5599-420a-a602-35d964e86de5 | rhcos         | active |
| 6b3dc49b-a53f-4cfc-98e0-9eb6925219de | rhel-7        | active |
| 965cb833-b97e-4488-9bc6-84495b9a9b7b | rhel-8        | active |
+--------------------------------------+---------------+--------+

Step 2: Launch CentOS 8 Instance from ISO

Login to your OpenStack Horizon dashboard.

deploy-openstack-devstack-ubuntu-login

Navigate to Project > Compute > Instances.

create-centos-8-openstack-template-01

Click on “Launch Instance“. Give the VM a name and description under details section.

create-centos-8-openstack-template-02-1024x518

Under source, select image as boot source, create Volume of 20GB then pick the CentOS 8 ISO image uploaded earlier.

create-centos-8-openstack-template-03-1024x518

Select flavor to use in the next page. I’ll use m1.small flavor which has 20GB of disk space, 1vcpu and 2GB of RAM. See how to create OpenStack Flavors for more details.

create-centos-8-openstack-template-04-1024x390

Choose network to use for VM creation.

create-centos-8-openstack-template-05-1024x406

Select security group to assign and other optional parameters then Launch the instance.

create-centos-8-openstack-template-06-1024x524

Wait for the instance to enter “Active” state.

create-centos-8-openstack-template-07-1024x342

Step 3: Create a Cinder Volume

Once the VM is in active state, create a volume then attach to the instance by following our guide How To Create OpenStack Cinder Volumes and Attach to a VM Instance to create and attach volume. This is where OS will be installed.

Step 4: Begin CentOS 8 Installation

Once the volume is attached, Click on the instance, then “Console” tab

create-centos-8-openstack-template-08-1024x576

Follow the standard CentOS installation as covered in:

Installing CentOS 8 Step by Step with Screenshots

But on Software selection, choose Server.

create-centos-8-openstack-template-09-1024x312

Choose the second disk added for OS installation.

create-centos-8-openstack-template-10-1024x458

Once you confirm all settings to be okay, begin installation of CentOS 8. Set root password.

create-centos-8-openstack-template-12-1024x244

Optionally create admin user, although cloud-init will be used to create a user later.

create-centos-8-openstack-template-13-1024x395

Finish CentOS 8 configuration.

create-centos-8-openstack-template-14-1024x640

Reboot the system once installation is complete.

create-centos-8-openstack-template-15-1024x597

The server attempt to boot from the ISO image once more. Press any key to stop the countdown.

create-centos-8-openstack-template-16-1024x541

Step 7: Terminate CentOS 8 Build Instance

We can now terminate the instance we created under Project > Compute > Instances

create-centos-8-openstack-template-17-1024x320

Select “CentOS8-build” and hit the “Delete Instances” button. Confirm deletion.

create-centos-8-openstack-template-18-1024x443

Step 8: Convert Volume to Qcow2 Image

Upload the Volume with CentOS 8 installation to Glance Image. This is done by navigating to Project > Compute > Volumes. Select the volume and click “UPLOAD TO IMAGE”

create-centos-8-openstack-template-19-1024x332

Give it a name and choose QCOW2 Disk Format.

create-centos-8-openstack-template-20-1024x617

Confirm if image was successfully uploaded under Project > Compute > Images

create-centos-8-openstack-template-21-1024x181

Select image and update metadata like below:

hypervisor_type: kvm auto_disk_config: true hw_qemu_guest_agent: true

To update image Metadata, enter metadata name in the custom box and click on the + button, then provide the value on the right side box.

create-centos-8-openstack-template-22-1024x880

Save settings when done. You can now delete the Volume on Project > Volumes > CentOS8-Template > Delete

Step 9: Create Instance from new Image

Create an instance from the image we just uploaded to Glance. Click on Project > Compute > Instances > Launch Instance.

create-centos-8-openstack-template-01 (1)

Give the instance the name “centOS8-build”, use m1.small flavor (One with 20GB disk), and select “Boot from image” and the “CentOS8-Template” image.

create-centos-8-openstack-template-23-1024x545

Launch the instance and wait for it to enter Active state. SSH to the new instance as “root“, using the root password used during setup, or access the instance using OpenStack Console.

$ ssh [email protected]
The authenticity of host '10.10.1.71 (10.10.1.71)' can't be established.
ECDSA key fingerprint is SHA256:9OOv/wC5aB5XownQPr4udNtiKvouvzr8UQoDcj6wdfE.
ECDSA key fingerprint is MD5:b6:32:c7:59:fd:25:48:07:11:f5:fb:cf:7e:cb:25:45.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.1.71' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sat Oct 26 21:44:14 2019 from 10.10.1.186
[[email protected] ~]# 

Prepare Instance to be used as OpenStack template.

Update system

sudo yum -y update

Install cloud-init, qemu guest agent, vim, bash-completion, cloud-utils-growpart.

sudo yum -y install vim bash-completion cloud-init qemu-guest-agent cloud-utils-growpart

Start and enable the qemu-guest-agent service:

sudo systemctl enable --now qemu-guest-agent.service

Disable the zeroconf route

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

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

Enable kernel console logging:

Open the file /etc/sysconfig/grub

sudo vim /etc/sysconfig/grub

Delete the rhgb quiet and add console=tty0 console=ttyS0,115200n8 to the option. Mine looks like below.

GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap console=tty0 console=ttyS0,115200n8"

Run the following command to save the changes:

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
done

Update cloud-init configuration file

You can change the name of the account used by cloud-init by editing the /etc/cloud/cloud.cfg file and adding a line with a different user.

sudo vim /etc/cloud/cloud.cfg

The default user created is cloud-user:

system_info:
  default_user:
    name: cloud-user
    lock_passwd: true
    gecos: Cloud User
    groups: [wheel, adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

Root account is disabled, to enable, set the line (Not recommended)

disable_root: 0

When done, delete the static network configuration file:

rm /etc/sysconfig/network-scripts/ifcfg-ens3

Then clear the bash history for root user.

rm /root/.bash_history; history -c

Step 10: Create Final CentOS 8 image

Navigate to Compute > Instances >centos8-build > Create Snapshot button.

create-centos-8-openstack-template-24-1024x452

Give it a name then create the Snapshot.

create-centos-8-openstack-template-25-1024x131

You can now delete the centos8-build Instance and centos8-template image created earlier. Use the Image created to launch CentOS 8 instances on OpenStack.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.