Openstack Image for Rocky Linux

Rocky qcow2 images can be downloaded by clicking on the download link below, or if you would like to step through the process of building or customising your own image you can follow the step-by-step instructions below.

How to Build Your own Rocky Images from the ISO file:

To setup your Rocky Linux image, first download the iso and import into Openstack:

curl -L -O https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-minimal.iso
openstack image create Rocky-8.4-iso --public --container-format bare --disk-format iso --file ./Rocky-8.4-x86_64-minimal.iso

Via the dashboard create a new instance using this image.

Attach a second volume to the instance as an installation target (if you do this after the boot you may need to rescan the drives during the installation if no disks are detected).

Proceed with the installation until it is complete. We added a Rocky user and gave that account a password – this will get cleaned up by sysprep later on.

Once the installation is complete you can shutdown the instance and detach the installation target volume.

Now, let’s boot up the new Rocky environment – where $VOLUME_ID is the cinder volume uuid which acted as the target installer for Rocky earlier:

openstack server create rocky-8.4-cloudimage --flavor m1.medium --network private --volume $VOLUME_ID

Once thats all up and running, we can ssh in to setup the system. First, log into the rocky OS and install cloud-init:

dnf install epel-release
dnf install cloud-init

On the cloud-init side, we set the following features in the configuration file:

/etc/cloud/cloud.cfg
system_info:
  default_user:
    name: rocky
    lock_passwd: true
    gecos: Cloud User
    groups: [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

Once we are happy with all of that, we can pull down the volume as a qcow2 image. Again, shut the instance down so the volume is not in a running state.

$VOLUME_ID is the block device we installed Rocky to earlier
$IMAGE_NAME whatever you wanted to call your Rocky image
$IMAGE_ID output from the cinder commands confirming the UUID of the newly created glance image file
$IMAGE_FILE_NAME is the local image qcow2 file name
cinder upload-to-image --disk-format qcow2 --force=True $VOLUME_ID $IMAGE_NAME
glance image-download $IMAGE_ID --file $IMAGE_FILE_NAME

You can now either copy the image over to an environment where the virt / libguestgs tools are present or install them locally. To install libguests-tools:

dnf install libguestfs-tools

And sysprep the image:

[root@rocky-8 rocky]# export LIBGUESTFS_BACKEND=direct
[root@rocky-8 rocky]# virt-sysprep -a ./rocky-8.4-cloudimage.qcow2
[ 0.0] Examining the guest ...
[ 117.5] Performing "abrt-data" ...
[ 118.1] Performing "backup-files" ...
[ 141.0] Performing "bash-history" ...
[ 141.3] Performing "blkid-tab" ...
[ 141.7] Performing "crash-data" ...
[ 141.9] Performing "cron-spool" ...
[ 143.1] Performing "dhcp-client-state" ...
[ 143.3] Performing "dhcp-server-state" ...
[ 143.3] Performing "dovecot-data" ...
[ 143.6] Performing "ipa-client" ...
[ 143.8] Performing "kerberos-hostkeytab" ...
[ 143.9] Performing "logfiles" ...
[ 149.1] Performing "machine-id" ...
[ 149.3] Performing "mail-spool" ...
[ 149.4] Performing "net-hostname" ...
[ 150.0] Performing "net-hwaddr" ...
[ 150.7] Performing "pacct-log" ...
[ 151.0] Performing "package-manager-cache" ...
[ 153.0] Performing "pam-data" ...
[ 153.2] Performing "passwd-backups" ...
[ 153.4] Performing "puppet-data-log" ...
[ 153.6] Performing "rh-subscription-manager" ...
[ 154.0] Performing "rhn-systemid" ...
[ 154.4] Performing "rpm-db" ...
[ 154.8] Performing "samba-db-log" ...
[ 155.3] Performing "script" ...
[ 155.3] Performing "smolt-uuid" ...
[ 155.7] Performing "ssh-hostkeys" ...
[ 156.1] Performing "ssh-userdir" ...
[ 156.6] Performing "sssd-db-log" ...
[ 156.9] Performing "tmp-files" ...
[ 158.0] Performing "udev-persistent-net" ...
[ 158.2] Performing "utmp" ...
[ 158.3] Performing "yum-uuid" ...
[ 158.5] Performing "customize" ...
[ 158.7] Setting a random seed
[ 159.1] Setting the machine ID in /etc/machine-id
[ 160.2] Performing "lvm-uuids" ...

Now, lets shrink down the image using virt-sparsify:

[root@rocky-8 rocky]# export TMPDIR=/scratch
[root@rocky-8 rocky]# virt-sparsify --compress rocky-8.4-cloudimage.qcow2 rocky-8.4-cloudimage-final.qcow2
[ 0.6] Create overlay file in /scratch to protect source disk
[ 1.7] Examine source disk
◓ 25% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════⟧ --:--
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[ 151.5] Fill free space in /dev/rl/root with zero
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[ 531.1] Clearing Linux swap on /dev/rl/swap
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[ 569.2] Fill free space in /dev/sda1 with zero
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[ 593.2] Copy to destination and make sparse
[1036.3] Sparsify operation completed with no errors.
virt-sparsify: Before deleting the old disk, carefully check that the
target disk boots and works correctly.

[root@rocky-8 rocky]# ls -lah

-rw-r--r--. 1 root root 908M Jun 29 06:27 rocky-8.4-cloudimage-final.qcow2
-rw-r--r--. 1 rocky rocky 2.2G Jun 29 05:08 rocky-8.4-cloudimage.qcow2

Very nice! Now, let’s get this up online for people to try out. Our ready-made image is available via the download button at the beginning and end of this blog post.

If you have any suggestions for improvements on the above – please feel free to comment below!

1 thought on “Openstack Image for Rocky Linux”

  1. Pingback: Rocky Linux for Openstack – Define Tech

Comments are closed.