Openstack image

The cloud image ( qcow2 ) to use in openstack is very large, there is a particular raison ?

$ du -sk centos/8/CentOS-8-ec2-8.1.1911-20200113.3.x86_64.qcow2
724300 centos/8/CentOS-8-ec2-8.1.1911-20200113.3.x86_64.qcow2

$ du -sk rocky/Rocky-8-GenericCloud-8.4-20210620.0.x86_64.qcow2
1282100 rocky/Rocky-8-GenericCloud-8.4-20210620.0.x86_64.qcow2

I ran this command to verify if it needed compressing first:

qemu-img convert -c -O qcow2 Rocky-8-GenericCloud-8.4-20210620.0.x86_64.qcow2 Rocky-8-GenericCloud-8.4-20210620.0.x86_64_shrunk.qcow2

but the image is already compressed since the size was the same after. I expect the difference is because amount of packages installed compared to the CentOS one is the reason why. You could run both images and then find out the differences by comparing the list of packages installed, or count the amount of packages installed, eg:

rpm -qa | wc -l

for both CentOS and Rocky images.

Thank a lot, strange deal, I hope that next losts some bytes …

Unlikely as I just tried with a custom minimal install. Here is a procedure to create your own openstack image:

I am using KVM with virt-manager to create this machine called rocky-minimal, since it will be a qcow2 image by default. I set the system to use RHEL 8.2 as the template for the hardware, with a disk size of 10GB.

Then we do a minimal install of Rocky. During install I created a user called “rocky”. On the disk, create a single standard partition for / using all the available size 10GiB and set the file system to ext4.

Reboot after install let’s update the system:

dnf update

let’s install some needed packages for using this image with OpenStack, etc. This means that SSH keys and other things can be injected when an instance is being created, as well as allowing OpenStack to grow the image to an appropriate disk size for the instance being created. acpid is needed so that OpenStack can shutdown the instance:

dnf install acpid cloud-init cloud-utils-growpart

Edit /etc/cloud/cloud.cfg and add the following:

users:
  - name: rocky

this user will be used in OpenStack for injecting an SSH key, and/or setting the password of the “rocky” user if you wish since this is also possible in OpenStack.

Reboot the server to use new installed kernel.
Remove old kernel and just leave the current one to save space. For mine on Rocky 8.4, I just did this:

dnf remove `rpm -qa | grep -i kernel | grep 305.3`

but in future that will vary from one version to the next. Then shutdown the server:

shutdown now

and let’s prep the image so that any MAC addresses, etc are removed - you use whatever name you called the VM in virt-manager (so in my example rocky-minimal):

virt-sysprep -d rocky-minimal

final step, compress the machine image:

qemu-img convert -c -O qcow2 rocky-minimal.qcow2 rocky-minimal-shrunk.qcow2

We can now see this based on what is looked like before:

-rw------- 1 root root  11G Jul 13 15:41 rocky-minimal.qcow2
-rw-r--r-- 1 root root 1.2G Jul 13 15:44 rocky-minimal-shrunk.qcow2

as you can see 1.2GB, so pretty much the same as the Rocky-8-GenericCloud image. If the install could be pruned down by checking the list of packages installed and removing unnecessary ones, in theory the image size could be reduced. I don’t see a 1.2GB image is being a major problem though.

Of course, this is not a big deal. The difference is only visible when you have the bad luck of stumbling upon a cloud hypervisor
and the image is missing in the cache.

Some news concerning this issue, I won nearly 200 Kb using the clean.sh script proposed by https://computingforgeeks.com/generate-rocky-linux-qcow2-image-for-openstack-kvm-qemu/

You can save a fair amount of disk space if you mount a tmpfs at /var/cache/dnf before you run `dnf update’