8 https://cloudinit.readthedocs.io[Cloud-Init] is the de facto
9 multi-distribution package that handles early initialization of a
10 virtual machine instance. Using Cloud-Init, configuration of network
11 devices and ssh keys on the hypervisor side is possible. When the VM
12 starts for the first time, the Cloud-Init software inside the VM will
15 Many Linux distributions provide ready-to-use Cloud-Init images, mostly
16 designed for 'OpenStack'. These images will also work with {pve}. While
17 it may seem convenient to get such ready-to-use images, we usually
18 recommended to prepare the images by yourself. The advantage is that you
19 will know exactly what you have installed, and this helps you later to
20 easily customize the image for your needs.
22 Once you have created such a Cloud-Init image we recommend to convert it
23 into a VM template. From a VM template you can quickly create linked
24 clones, so this is a fast method to roll out new VM instances. You just
25 need to configure the network (and maybe the ssh keys) before you start
28 We recommend using SSH key-based authentication to login to the VMs
29 provisioned by Cloud-Init. It is also possible to set a password, but
30 this is not as safe as using SSH key-based authentication because {pve}
31 needs to store an encrypted version of that password inside the
34 {pve} generates an ISO image to pass the Cloud-Init data to the VM. For
35 that purpose, all Cloud-Init VMs need to have an assigned CD-ROM drive.
36 Usually, a serial console should be added and used as a display. Many Cloud-Init
37 images rely on this, it is a requirement for OpenStack. However, other images
38 might have problems with this configuration. Switch back to the default display
39 configuration if using a serial console doesn't work.
42 Preparing Cloud-Init Templates
43 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 The first step is to prepare your VM. Basically you can use any VM.
46 Simply install the Cloud-Init packages inside the VM that you want to
47 prepare. On Debian/Ubuntu based systems this is as simple as:
50 apt-get install cloud-init
53 WARNING: This command is *not* intended to be executed on the {pve} host, but
56 Already many distributions provide ready-to-use Cloud-Init images (provided
57 as `.qcow2` files), so alternatively you can simply download and
58 import such images. For the following example, we will use the cloud
59 image provided by Ubuntu at https://cloud-images.ubuntu.com.
63 wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
66 qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0
68 # import the downloaded disk to local-lvm storage
69 qm importdisk 9000 bionic-server-cloudimg-amd64.img local-lvm
71 # finally attach the new disk to the VM as scsi drive
72 qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
75 NOTE: Ubuntu Cloud-Init images require the `virtio-scsi-pci`
76 controller type for SCSI drives.
78 .Add Cloud-Init CD-ROM drive
80 [thumbnail="screenshot/gui-cloudinit-hardware.png"]
82 The next step is to configure a CD-ROM drive, which will be used to pass
83 the Cloud-Init data to the VM.
86 qm set 9000 --ide2 local-lvm:cloudinit
89 To be able to boot directly from the Cloud-Init image, set the `boot` parameter
90 to `order=scsi0` to restrict BIOS to boot from this disk only. This will speed
91 up booting, because VM BIOS skips the testing for a bootable CD-ROM.
94 qm set 9000 --boot order=scsi0
97 For many Cloud-Init images, it is required to configure a serial console and use
98 it as a display. If the configuration doesn't work for a given image however,
99 switch back to the default display instead.
102 qm set 9000 --serial0 socket --vga serial0
105 In a last step, it is helpful to convert the VM into a template. From
106 this template you can then quickly create linked clones.
107 The deployment from VM templates is much faster than creating a full
114 Deploying Cloud-Init Templates
115 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 [thumbnail="screenshot/gui-cloudinit-config.png"]
119 You can easily deploy such a template by cloning:
122 qm clone 9000 123 --name ubuntu2
125 Then configure the SSH public key used for authentication, and configure
129 qm set 123 --sshkey ~/.ssh/id_rsa.pub
130 qm set 123 --ipconfig0 ip=10.0.10.123/24,gw=10.0.10.1
133 You can also configure all the Cloud-Init options using a single command
134 only. We have simply split the above example to separate the
135 commands for reducing the line length. Also make sure to adopt the IP
136 setup for your specific environment.
139 Custom Cloud-Init Configuration
140 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142 The Cloud-Init integration also allows custom config files to be used instead
143 of the automatically generated configs. This is done via the `cicustom`
144 option on the command line:
147 qm set 9000 --cicustom "user=<volume>,network=<volume>,meta=<volume>"
150 The custom config files have to be on a storage that supports snippets and have
151 to be available on all nodes the VM is going to be migrated to. Otherwise the
152 VM won't be able to start.
156 qm set 9000 --cicustom "user=local:snippets/userconfig.yaml"
159 There are three kinds of configs for Cloud-Init. The first one is the `user`
160 config as seen in the example above. The second is the `network` config and
161 the third the `meta` config. They can all be specified together or mixed
162 and matched however needed.
163 The automatically generated config will be used for any that don't have a
164 custom config file specified.
166 The generated config can be dumped to serve as a base for custom configs:
169 qm cloudinit dump 9000 user
172 The same command exists for `network` and `meta`.
175 Cloud-Init specific Options
176 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
178 include::qm-cloud-init-opts.adoc[]
186 * link:/wiki/Qemu/KVM_Virtual_Machines[Qemu/KVM Virtual Machines]