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:
Install the
diskimage-builderpackage:# yum install diskimage-builder
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>
Execute the following command to build a disk image with installed
cloud-initfor the desired Linux guest. For example:# disk-image-create vm centos7 -t qcow2 -o centos7
where
centos7is the name of a guest OS. Can be one of the following:centos6,centos7,debian,rhel7, orubuntu.By default, using the
ubuntuelement will create a disk image for Ubuntu 16.04. To build the Ubuntu 18.04 disk image, add theDIB_RELEASE=bionicto the command as follows:DIB_RELEASE=bionic disk-image-create vm ubuntu -t qcow2 -o ubuntu18.-osets the name for the resulting disk image file.
Upload the created disk image using the
vinfratool to the compute cluster:# vinfra service compute image create centos7-image --os-distro centos7 \ --disk-format qcow2 --file centos7.qcow2
where
centos7-imageis the name of a new image.centos7is the OS distribution. Can be one of the following:centos6,centos7,debian9,rhel7,ubuntu16.04, andubuntu18.04.centos7.qcow2is the QCOW2-image created on step 3.
Create the
user-dataconfiguration file with a custom user account:# cat <<EOF > user-data #cloud-config user: myuser password: password chpasswd: {expire: False} ssh_pwauth: True EOFwhere
myuseris the name of a custom user andpasswordis a password for the account.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-vmis the name of a new VM,user-datais the configuration file created in step 5,centos7-imageis the image added to the compute cluster in step 4.
For more information on managing compute objects via the
vinfratool, see Managing Compute Cluster.