Ubuntu Cloud Images

Prerequisites: You have KVM set up and can define and start guests.

Ubuntu Cloud Images can be found here. Their intended use is in managed environments like OpenStack, but they can be deployed as single guest instances, also known as nocloud. They provide (compared to the regular Ubuntu install images) a rather minimalistic installation, which makes it ideal for mass deployments. These images contain the cloud-init tool, which reads a configuration from CD-ROMs or disks and allows simple configuration and provisioning of images. See the cloud-init webpage for further details.

Before you start, make sure to install cloud-image-utils:
   $ sudo apt install cloud-image-utils

It is recommended to pick
  • an image of a recent Ubuntu version to benefit from the most recent features available upstream,
  • a release version rather than a snapshot for maximum stability, and
  • an image with extension .img, as these do not require any additional processing.
For example, let's pick a release image for Ubuntu 17.10 and download directly to our target directory:
   $ sudo wget -P /var/lib/libvirt/images https://cloud-images.ubuntu.com/\
          releases/17.10/release/ubuntu-17.10-server-cloudimg-s390x.img
Per default, the Ubuntu Cloud Images are not enabled for ssh login, and have not password set. Therefore, we need to initialize the password accordingly. Create a file clguest.cfg with the following content:
   # cloud-config
   password: your_password
   chpasswd: { expire: False }
   ssh_pwauth: True
Next, create a CD-ROM image that we will use to initialize our guest:
   $ sudo cloud-localds -H clguest /var/lib/libvirt/images/clguest.img clguest.cfg
Finally, let's define our guest. We set the cloud image file that we downloaded as our root disk, and attach the cloud config image as (naturally) a CD-ROM. Below is a sample clguest.xml for Ubuntu. If you plan to run an Ubuntu Cloud Image in a different Linux distribution, use a working guest definition and adjust the <disk> sections accordingly.
   <domain type='kvm'>
     <name>clguest</name>
     <memory unit='GiB'>4</memory>
     <vcpu>2</vcpu>
     <os>
       <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
     </os>
     <iothreads>1</iothreads>
     <on_poweroff>destroy</on_poweroff>
     <on_reboot>restart</on_reboot>
     <on_crash>preserve</on_crash>
     <devices>
       <disk type='file' device='disk'>
         <driver name='qemu' type='qcow2' io='native' cache='none' iothread='1'/>
         <source file='/var/lib/libvirt/images/ubuntu-17.10-server-cloudimg-s390x.img'/>
         <target dev='vda' bus='virtio'/>
       </disk>
       <disk type='file' device='cdrom'>
         <source file='/var/lib/libvirt/images/clguest.img'/>
         <target dev='sda' bus='scsi'/>
         <readonly/>
       </disk>
       <interface type='bridge'>
         <source bridge='virbr0'/>
         <model type='virtio'/>
       </interface>
       <console type='pty'>
         <target type='sclp'/>
       </console>
       <memballoon model='none'/> 
     </devices>
   </domain>
Now define and start the guest as usual
   $ virsh define clguest.xml
   $ virsh start --console clguest
and login as user ubuntu using your_password:

No comments:

Post a Comment