How to Configure Proxmox with Cloud-init?


Step 1: Download the cloud image  

I directly downloaded the Ubuntu 18.04 image here. You can also use “wget” to download the image directly in PVE. The images are all direct links.

Step 2: Import the cloud image into PVE  

You can share the image via SMB to PVE. If you used “wget” in the previous step, no need to import it.

Step 3: Create a Virtual Machine  

Create a VM. Make sure to select VirtIO SCSI.

Next, remove the original hard disk.

First, detach it and then delete it.

Add the following devices: USB device, Serial port device, Cloud-init Drive.

Step 4: Import the cloud image into the VM  

Switch to the directory where the cloud image is located:  

“cd /cloudimages” 

Rename the cloud image for convenience:  

“mv ubuntu-18.04-server-cloudimg-amd64.vmdk ubuntu18.04.vmdk”

Add the cloud image to the VM (command syntax can be found in Importing Disk Images into PVE):

“qm importdisk 101 ubuntu18.04.vmdk NVME –format=qcow2”  

After successful import, the disk will appear in the VM hardware section of the PVE panel as unused.  

Double-click this unused disk to use it (it’s best to choose SCSI).

Step 5: Set Boot Order  

In the VM’s configuration page:  

Options > Boot Order > Select the imported disk as the boot device.

Step 6: Configure Cloud-init  

User: Enter the username.  

Password: Enter the user password.  

DNS Domain and DNS Server: Enter the DNS. If DHCP is available, you can skip this. If set, it will be static DNS.  

SSH Public Key: Enter the SSH public key, which can be generated via Xshell. For details, see Generating SSH Keys with Xshell.  

IP Configuration: You can set a static IP here, or use DHCP.

Once configured, Cloud-init will set the VM’s name as the hostname.

Step 7: Power on and test  

Step 8: Enable password login  

Modify “sshd_config”:

“vi /etc/ssh/sshd_config”

Change:  

“PermitRootLogin yes”  

“PasswordAuthentication yes”  

Restart the SSH service.

Step 9: Test expanding the disk  

Shut down the VM, add 10GB to the disk, then power on the VM again.

Step 10: Clone the VM to a template  

Then you can link or fully clone the template.


Leave a Reply

Your email address will not be published. Required fields are marked *