]> git.proxmox.com Git - pve-docs.git/blame - qm-cloud-init.adoc
cloud init: use expected disk number in example
[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.
2050eb19
FE
36Usually, a serial console should be added and used as a display. Many Cloud-Init
37images rely on this, it is a requirement for OpenStack. However, other images
38might have problems with this configuration. Switch back to the default display
39configuration if using a serial console doesn't work.
7eb69fd2
DM
40
41
85d697af 42Preparing Cloud-Init Templates
a3cc9331 43~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7eb69fd2 44
85d697af
TL
45The first step is to prepare your VM. Basically you can use any VM.
46Simply install the Cloud-Init packages inside the VM that you want to
7eb69fd2
DM
47prepare. On Debian/Ubuntu based systems this is as simple as:
48
49----
50apt-get install cloud-init
51----
52
88cb1214
FE
53WARNING: This command is *not* intended to be executed on the {pve} host, but
54only inside the VM.
55
85d697af
TL
56Already many distributions provide ready-to-use Cloud-Init images (provided
57as `.qcow2` files), so alternatively you can simply download and
58import such images. For the following example, we will use the cloud
59image provided by Ubuntu at https://cloud-images.ubuntu.com.
7eb69fd2
DM
60
61----
62# download the image
63wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
64
65# create a new VM
66qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0
67
68# import the downloaded disk to local-lvm storage
69qm importdisk 9000 bionic-server-cloudimg-amd64.img local-lvm
70
71# finally attach the new disk to the VM as scsi drive
593bdd7d 72qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
7eb69fd2
DM
73----
74
85d697af 75NOTE: Ubuntu Cloud-Init images require the `virtio-scsi-pci`
7eb69fd2
DM
76controller type for SCSI drives.
77
3a433e9b 78.Add Cloud-Init CD-ROM drive
d528c7ba 79
1ff5e4e8 80[thumbnail="screenshot/gui-cloudinit-hardware.png"]
d528c7ba 81
3a433e9b 82The next step is to configure a CD-ROM drive, which will be used to pass
85d697af 83the Cloud-Init data to the VM.
7eb69fd2
DM
84
85----
86qm set 9000 --ide2 local-lvm:cloudinit
87----
88
44562c3b
FE
89To be able to boot directly from the Cloud-Init image, set the `boot` parameter
90to `order=scsi0` to restrict BIOS to boot from this disk only. This will speed
91up booting, because VM BIOS skips the testing for a bootable CD-ROM.
7eb69fd2
DM
92
93----
44562c3b 94qm set 9000 --boot order=scsi0
7eb69fd2
DM
95----
96
2050eb19
FE
97For many Cloud-Init images, it is required to configure a serial console and use
98it as a display. If the configuration doesn't work for a given image however,
99switch back to the default display instead.
7eb69fd2
DM
100
101----
102qm set 9000 --serial0 socket --vga serial0
103----
104
85d697af
TL
105In a last step, it is helpful to convert the VM into a template. From
106this template you can then quickly create linked clones.
107The deployment from VM templates is much faster than creating a full
108clone (copy).
7eb69fd2
DM
109----
110qm template 9000
111----
112
113
85d697af 114Deploying Cloud-Init Templates
a3cc9331 115~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7eb69fd2 116
1ff5e4e8 117[thumbnail="screenshot/gui-cloudinit-config.png"]
d528c7ba 118
85d697af 119You can easily deploy such a template by cloning:
7eb69fd2
DM
120
121----
122qm clone 9000 123 --name ubuntu2
123----
124
85d697af
TL
125Then configure the SSH public key used for authentication, and configure
126the IP setup:
7eb69fd2
DM
127
128----
129qm set 123 --sshkey ~/.ssh/id_rsa.pub
130qm set 123 --ipconfig0 ip=10.0.10.123/24,gw=10.0.10.1
131----
132
85d697af 133You can also configure all the Cloud-Init options using a single command
5f318cc0 134only. We have simply split the above example to separate the
85d697af
TL
135commands for reducing the line length. Also make sure to adopt the IP
136setup for your specific environment.
7eb69fd2 137
d528c7ba 138
a3e7e4e3
ML
139Custom Cloud-Init Configuration
140~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141
142The Cloud-Init integration also allows custom config files to be used instead
143of the automatically generated configs. This is done via the `cicustom`
144option on the command line:
145
146----
147qm set 9000 --cicustom "user=<volume>,network=<volume>,meta=<volume>"
148----
149
150The custom config files have to be on a storage that supports snippets and have
151to be available on all nodes the VM is going to be migrated to. Otherwise the
152VM won't be able to start.
153For example:
154
155----
156qm set 9000 --cicustom "user=local:snippets/userconfig.yaml"
157----
158
159There are three kinds of configs for Cloud-Init. The first one is the `user`
160config as seen in the example above. The second is the `network` config and
161the third the `meta` config. They can all be specified together or mixed
162and matched however needed.
163The automatically generated config will be used for any that don't have a
164custom config file specified.
165
166The generated config can be dumped to serve as a base for custom configs:
167
168----
169qm cloudinit dump 9000 user
170----
171
172The same command exists for `network` and `meta`.
173
174
7eb69fd2
DM
175Cloud-Init specific Options
176~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
178include::qm-cloud-init-opts.adoc[]
16b4185a
DM
179
180
181ifdef::wiki[]
182
183See Also
184~~~~~~~~
185
186* link:/wiki/Qemu/KVM_Virtual_Machines[Qemu/KVM Virtual Machines]
187
188endif::wiki[]