]> git.proxmox.com Git - pve-docs.git/blame - qm-cloud-init.adoc
backup: clarify that CLI means FS-level and highlight retention-note
[pve-docs.git] / qm-cloud-init.adoc
CommitLineData
7eb69fd2
DM
1[[qm_cloud_init]]
2Cloud-Init Support
3------------------
4ifdef::wiki[]
5:pve-toplevel:
6endif::wiki[]
7
a55d30db 8https://cloudinit.readthedocs.io[Cloud-Init] is the de facto
7eb69fd2 9multi-distribution package that handles early initialization of a
85d697af
TL
10virtual machine instance. Using Cloud-Init, configuration of network
11devices and ssh keys on the hypervisor side is possible. When the VM
12starts for the first time, the Cloud-Init software inside the VM will
13apply those settings.
14
15Many Linux distributions provide ready-to-use Cloud-Init images, mostly
16designed for 'OpenStack'. These images will also work with {pve}. While
17it may seem convenient to get such ready-to-use images, we usually
18recommended to prepare the images by yourself. The advantage is that you
19will know exactly what you have installed, and this helps you later to
20easily customize the image for your needs.
21
22Once you have created such a Cloud-Init image we recommend to convert it
23into a VM template. From a VM template you can quickly create linked
24clones, so this is a fast method to roll out new VM instances. You just
25need to configure the network (and maybe the ssh keys) before you start
26the new VM.
27
28We recommend using SSH key-based authentication to login to the VMs
7eb69fd2 29provisioned by Cloud-Init. It is also possible to set a password, but
85d697af
TL
30this is not as safe as using SSH key-based authentication because {pve}
31needs to store an encrypted version of that password inside the
32Cloud-Init data.
7eb69fd2 33
85d697af 34{pve} generates an ISO image to pass the Cloud-Init data to the VM. For
3a433e9b 35that purpose, all Cloud-Init VMs need to have an assigned CD-ROM drive.
85d697af
TL
36Also many Cloud-Init images assume to have a serial console, so it is
37recommended to add a serial console and use it as display for those VMs.
7eb69fd2
DM
38
39
85d697af 40Preparing Cloud-Init Templates
a3cc9331 41~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7eb69fd2 42
85d697af
TL
43The first step is to prepare your VM. Basically you can use any VM.
44Simply install the Cloud-Init packages inside the VM that you want to
7eb69fd2
DM
45prepare. On Debian/Ubuntu based systems this is as simple as:
46
47----
48apt-get install cloud-init
49----
50
85d697af
TL
51Already many distributions provide ready-to-use Cloud-Init images (provided
52as `.qcow2` files), so alternatively you can simply download and
53import such images. For the following example, we will use the cloud
54image provided by Ubuntu at https://cloud-images.ubuntu.com.
7eb69fd2
DM
55
56----
57# download the image
58wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
59
60# create a new VM
61qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0
62
63# import the downloaded disk to local-lvm storage
64qm importdisk 9000 bionic-server-cloudimg-amd64.img local-lvm
65
66# finally attach the new disk to the VM as scsi drive
67qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-1
68----
69
85d697af 70NOTE: Ubuntu Cloud-Init images require the `virtio-scsi-pci`
7eb69fd2
DM
71controller type for SCSI drives.
72
3a433e9b 73.Add Cloud-Init CD-ROM drive
d528c7ba 74
1ff5e4e8 75[thumbnail="screenshot/gui-cloudinit-hardware.png"]
d528c7ba 76
3a433e9b 77The next step is to configure a CD-ROM drive, which will be used to pass
85d697af 78the Cloud-Init data to the VM.
7eb69fd2
DM
79
80----
81qm set 9000 --ide2 local-lvm:cloudinit
82----
83
85d697af
TL
84To be able to boot directly from the Cloud-Init image, set the
85`bootdisk` parameter to `scsi0`, and restrict BIOS to boot from disk
86only. This will speed up booting, because VM BIOS skips the testing for
3a433e9b 87a bootable CD-ROM.
7eb69fd2
DM
88
89----
90qm set 9000 --boot c --bootdisk scsi0
91----
92
85d697af
TL
93Also configure a serial console and use it as a display. Many Cloud-Init
94images rely on this, as it is an requirement for OpenStack images.
7eb69fd2
DM
95
96----
97qm set 9000 --serial0 socket --vga serial0
98----
99
85d697af
TL
100In a last step, it is helpful to convert the VM into a template. From
101this template you can then quickly create linked clones.
102The deployment from VM templates is much faster than creating a full
103clone (copy).
7eb69fd2
DM
104----
105qm template 9000
106----
107
108
85d697af 109Deploying Cloud-Init Templates
a3cc9331 110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7eb69fd2 111
1ff5e4e8 112[thumbnail="screenshot/gui-cloudinit-config.png"]
d528c7ba 113
85d697af 114You can easily deploy such a template by cloning:
7eb69fd2
DM
115
116----
117qm clone 9000 123 --name ubuntu2
118----
119
85d697af
TL
120Then configure the SSH public key used for authentication, and configure
121the IP setup:
7eb69fd2
DM
122
123----
124qm set 123 --sshkey ~/.ssh/id_rsa.pub
125qm set 123 --ipconfig0 ip=10.0.10.123/24,gw=10.0.10.1
126----
127
85d697af 128You can also configure all the Cloud-Init options using a single command
5f318cc0 129only. We have simply split the above example to separate the
85d697af
TL
130commands for reducing the line length. Also make sure to adopt the IP
131setup for your specific environment.
7eb69fd2 132
d528c7ba 133
a3e7e4e3
ML
134Custom Cloud-Init Configuration
135~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
137The Cloud-Init integration also allows custom config files to be used instead
138of the automatically generated configs. This is done via the `cicustom`
139option on the command line:
140
141----
142qm set 9000 --cicustom "user=<volume>,network=<volume>,meta=<volume>"
143----
144
145The custom config files have to be on a storage that supports snippets and have
146to be available on all nodes the VM is going to be migrated to. Otherwise the
147VM won't be able to start.
148For example:
149
150----
151qm set 9000 --cicustom "user=local:snippets/userconfig.yaml"
152----
153
154There are three kinds of configs for Cloud-Init. The first one is the `user`
155config as seen in the example above. The second is the `network` config and
156the third the `meta` config. They can all be specified together or mixed
157and matched however needed.
158The automatically generated config will be used for any that don't have a
159custom config file specified.
160
161The generated config can be dumped to serve as a base for custom configs:
162
163----
164qm cloudinit dump 9000 user
165----
166
167The same command exists for `network` and `meta`.
168
169
7eb69fd2
DM
170Cloud-Init specific Options
171~~~~~~~~~~~~~~~~~~~~~~~~~~~
172
173include::qm-cloud-init-opts.adoc[]
16b4185a
DM
174
175
176ifdef::wiki[]
177
178See Also
179~~~~~~~~
180
181* link:/wiki/Qemu/KVM_Virtual_Machines[Qemu/KVM Virtual Machines]
182
183endif::wiki[]