8.5. Creating Linux Templates

If you do not have a ready Linux template, you can build one with the diskimage-builder tool. The disk image is created with only the root user that has neither password nor SSH keys. You can use the user data and cloud-init methods to perform initial configuration tasks on VMs that will be deployed from the disk image, for example, create custom user accounts. For more options to customize a VM during boot, refer to the cloud-init documentation.

To create a template and deploy a VM from it, do as follows:

  1. Install the diskimage-builder package:

    # yum install diskimage-builder
    
  2. For the RHEL 7 guest OS, download the cloud image from the Red Hat Customer Portal (login required) and execute:

    # export DIB_LOCAL_IMAGE=<path_to_rhel7_image>
    
  3. Execute the following command to build a disk image with installed cloud-init for the desired Linux guest. For example:

    # disk-image-create vm centos7 -t qcow2 -o centos7
    

    where

    • centos7 is the name of a guest OS. Can be one of the following: centos6, centos7, debian, rhel7, or ubuntu.

      By default, using the ubuntu element will create a disk image for Ubuntu 16.04. To build the Ubuntu 18.04 disk image, add the DIB_RELEASE=bionic to the command as follows: DIB_RELEASE=bionic disk-image-create vm ubuntu -t qcow2 -o ubuntu18.

    • -o sets the name for the resulting disk image file.

  4. Upload the created disk image using the vinfra tool to the compute cluster:

    # vinfra service compute image create centos7-image --os-distro centos7 \
    --disk-format qcow2 --file centos7.qcow2
    

    where

    • centos7-image is the name of a new image.
    • centos7 is the OS distribution. Can be one of the following: centos6, centos7, debian9, rhel7, ubuntu16.04, and ubuntu18.04.
    • centos7.qcow2 is the QCOW2-image created on step 3.
  5. Create the user-data configuration file with a custom user account:

    # cat <<EOF > user-data
    #cloud-config
    user: myuser
    password: password
    chpasswd: {expire: False}
    ssh_pwauth: True
    EOF
    

    where myuser is the name of a custom user and password is a password for the account.

  6. Launch the deployment of a VM from the disk image using the configuration file as user data:

    # vinfra service compute server create centos7-vm --flavor medium --network public \
    --user-data user-data --volume source=image,id=centos7-image,size=10
    

    where

    • centos7-vm is the name of a new VM,
    • user-data is the configuration file created in step 5,
    • centos7-image is the image added to the compute cluster in step 4.

    For more information on managing compute objects via the vinfra tool, see Managing Compute Cluster.