Obtaining Linux templates
As all Linux guests have OpenSSH Server preinstalled by default, you only need to make sure a Linux template has cloud-init installed.
The easiest way to get a Linux template with cloud-init installed is to obtain it from its official repository or build one with the diskimage-builder
tool. You can also create a Linux template from an existing boot volume.
Limitations
- The disk image is created with only the root user that has neither password nor SSH keys. You can use the
user data
andcloud-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 build a Linux template
-
Install the
diskimage-builder
package:# 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
disk-image-create
command to build a disk image with installedcloud-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
, orubuntu
.By default, using the
ubuntu
element will create a disk image for Ubuntu 16.04. To build the Ubuntu 18.04 disk image, add theDIB_RELEASE=bionic
to the command:DIB_RELEASE=bionic disk-image-create vm ubuntu -t qcow2 -o ubuntu18
. -
-o
sets the name for the resulting disk image file.
-
-
Upload the created disk image by 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
, andubuntu18.04
.centos7.qcow2
is the QCOW2-image created on step 3.
To deploy a virtual machine from the uploaded template
-
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 andpassword
is a password for the account. -
Launch the deployment of a VM from the disk image by 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=10where
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.