C.8. Completing the Red Hat Enterprise Linux 7 image

  1. Update the system:

    # {package-update}
  2. Install the cloud-init packages:

    # yum install cloud-utils-growpart cloud-init
  3. Open the /etc/cloud/cloud.cfg configuration file:

    # vi /etc/cloud/cloud.cfg
  4. Under the heading cloud_init_modules, add:

    - resolv-conf

    The resolv-conf option automatically configures the resolv.conf when an instance boots for the first time. This file contains information related to the instance such as nameservers, domain and other options.

  5. Open the /etc/sysconfig/network file:

    # vi /etc/sysconfig/network
  6. Add the following line to avoid problems accessing the EC2 metadata service:

    NOZEROCONF=yes
  7. Un-register the virtual machine so that the resulting image does not contain the same subscription details for every instance cloned based on it:

    # subscription-manager repos --disable=*
    # subscription-manager unregister
  8. Power off the instance:

    # poweroff
  9. On your Red Hat Enterprise Linux Workstation, connect to the terminal as the root user and navigate to the /var/lib/libvirt/images/ directory:

    [root@host]# cd /var/lib/libvirt/images/
  10. Reset and clean the image using the virt-sysprep command so it can be used to create instances without issues:

    [root@host]# virt-sysprep -d rhel7
  11. Reduce image size using the virt-sparsify command. This command converts any free space within the disk image back to free space within the host:

    [root@host]# virt-sparsify --compress rhel7.qcow2 rhel7-cloud.qcow2

    This creates a new rhel7-cloud.qcow2 file in the location where you enter the command.