Preparing Linux templates
As all Linux guests have OpenSSH Server preinstalled by default, you only need to ensure that a Linux template has cloud-init installed.
Cloud-init is required to configure user credentials and SSH access for virtual machines created from cloud images.
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
- Disk images created with cloud-init typically contain only the root user without a predefined password or SSH keys. You can use user data and cloud-init 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-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
disk-image-createcommand to build a disk image with installedcloud-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, run: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 by 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.
After the template is uploaded, you can use it to deploy virtual machines.
Using cloud-init with Linux cloud images
When deploying virtual machines from Linux cloud images (for example, Debian or Ubuntu), cloud-init applies the initial system configuration.
Cloud images do not contain predefined credentials. User accounts, passwords, and SSH settings are defined through cloud-init.
Access to such virtual machines is typically provided in one of the following ways:
- by injecting an SSH key
- by specifying user credentials in a cloud-init configuration
SSH keys selected at deployment are automatically injected into the guest operating system via cloud-init.
If neither a cloud-init configuration nor an SSH key is provided, you may not be able to log in to the virtual machine.
The following example creates a user account, sets a password, and enables SSH password authentication:
#cloud-config
users:
- name: clouduser
groups: sudo
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
ssh_pwauth: true
chpasswd:
expire: false
list: |
clouduser:<password>
runcmd:
- systemctl restart ssh
Replace <password> with a secure password.
Cloud-init configuration is provided when creating the virtual machine. For details, refer to Creating virtual machines.