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.
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.
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.
Navigate to Project > Compute > Instances.
Click on “Launch Instance“. Give the VM a name and description under details section.
Under source, select image as boot source, create Volume of 20GB then pick the CentOS 8 ISO image uploaded earlier.
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.
Choose network to use for VM creation.
Select security group to assign and other optional parameters then Launch the instance.
Wait for the instance to enter “Active” state.
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
Follow the standard CentOS installation as covered in:
Installing CentOS 8 Step by Step with Screenshots
But on Software selection, choose Server.
Choose the second disk added for OS installation.
Once you confirm all settings to be okay, begin installation of CentOS 8. Set root password.
Optionally create admin user, although cloud-init will be used to create a user later.
Finish CentOS 8 configuration.
Reboot the system once installation is complete.
The server attempt to boot from the ISO image once more. Press any key to stop the countdown.
Step 7: Terminate CentOS 8 Build Instance
We can now terminate the instance we created under Project > Compute > Instances
Select “CentOS8-build” and hit the “Delete Instances” button. Confirm deletion.
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”
Give it a name and choose QCOW2 Disk Format.
Confirm if image was successfully uploaded under Project > Compute > Images
Select image and update metadata like below:
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.
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.
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.
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.
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
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)
When done, delete the static network configuration file:
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.
Give it a name then create the Snapshot.
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.