Quick deployment of Debian cloud image in Proxmox with cloud-init
Introduction
This post demonstrates how to quickly create and afterwards clone virtual machine in Proxmox using Debian cloud image. When not using cloud image, more time must be spent after cloning virtual machine: you need to recreate SSH keys (cloning virtual machine doesn't change host SSH keys and that can cause problems with SSH connection to VMs cloned from same template machine), create new user with SSH access, change partition size when you resize disk in Proxmox, set hostname. All of this can be easily achieved with Debian cloud image because it is using cloud-init and Proxmox has built in support for it. This instruction is for creating virtual machine from cloud image on Proxmox with ZFS filesystem.
Software used: Proxmox 8, Debian 12 cloud image
General info
Warning
One important thing to note is that by default Proxmox cloud-init configuration sets up sudo command in the virtual machine so that it does not require entering a password. Machines with such configuration are suitable for testing, automation, CI/CD and even then it's recommended to restrict what actions user can do with sudo without password. You can change this behavior with custom cloud-init configuration, but this requires creating new files that you must manage outside of Proxmox backup system. Such configuration is beyond the scope of this post.
Download Debian cloud image
Create ZFS dataset in Proxmox for downloading cloud images.
# zfs create datapool/cloud-images -o recordsize=1M
datapool - your ZFS zpool name
cloud-images - enter name for your dataset
-o recordsize - ZFS dataset record size, for large files like backups and ISO images 1M can be a good choice
Download latest cloud image in raw format from Debian Official Cloud Images web page (for Debian 12 it will be in bookworm path).
In this post genericcloud cloud image will be used.
wget -P /path/to/save/ https://URL/image.raw
# wget -P /datapool/cloud-images/ https://cloud.debian.org/images/cloud/bookworm/<date-time>/debian-12-genericcloud-amd64-<date-time>.raw
-P - folder where the file will be downloaded
Note
Debian web page has following cloud image types:
- generic: Should run in any environment using cloud-init, for e.g. OpenStack, DigitalOcean and also on bare metal.
- genericcloud: Similar to generic. Should run in any virtualised environment. Is smaller than
genericby excluding drivers for physical hardware. - nocloud: Mostly useful for testing the build process itself. Doesn't have cloud-init installed, but instead allows root login without a password.
- azure: Optimized for the Microsoft Azure environment
- ec2: Optimized for the Amazon EC2
Create virtual machine
Create a new virtual machine in Proxmox without assigning a virtual disk.
- Click button
Create VM:- Tab
General:Node- select your Proxmox hostVM ID- enter ID for your virtual machine (in Proxmox it is a number)Name- enter name for your virtual machine, it will be your machine hostname
- Tab
OS:- select
Do not use any media - in other fields leave default values
- select
- Tab
System:Qemu Agent- check this field- in other fields leave default values
- Tab
Disks:- delete default disk
scsci0
- delete default disk
- Tab
CPU:Cores- select number of cores you want to assign to virtual machineType- selecthostif you want maximum performance- in other fields leave default values
- Tab
Memory:Memory (MiB)- enter amount of RAM you want to assign to virtual machine
- Tab
Network:Bridge- select network bridge for use by this virtual machineVLAN Tag- enter VLAN number if you separate virtual machines from other parts of your network using VLANs. If you don't use VLANs leave this field empty.- in other fields leave default values
- Tab
Import Debian cloud image to Proxmox virtual machine
Import downloaded cloud image using command:
qm disk import <vmID> <image_file> <Proxmox_storage>
# qm disk import 100 /datapool/cloud-images/debian-12-genericcloud-amd64-xxx.raw local-zfs
100 - ID of created virtual machine in Proxomx
local-zfs - storage in Proxmox to which import downloaded cloud image as virtual machine disk
Next go to created virtual machine:
Datacenter> your Proxmox host > virtual machine >Hardware> selectUnused Disk 0> clickEdit> checkDiscard> clickAddDatacenter> your Proxmox host > virtual machine >Options> selectBoot Order> clickEdit> checkscsci0and drag and drop it as first disk to boot
Discard - discard unused blocks on mounted filesystem. This can save space on host when you delete data from virtual machine, because image can then be automatically shrunk.
Configuration of Debian virtual machine
Remove hardware not needed by virtual machine
You can remove CD/DVD drive as it won't be needed by this machine.
Datacenter> your Proxmox host > virtual machine >Hardware> selectCD/DVD drive> clickRemove
Resize disk
Datacenter> your Proxmox host > virtual machine >Hardware> selectHard Disk (scsi0)> clickDisk Action> selectResize>Size Increment (GiB)- enter number in gigabytes by how much to increase the disk
Cloud-init
Datacenter> your Proxmox host > virtual machine >Hardware> clickAdd> selectCloudInit Drive>Storage- select storage where you keep your virtual machineDatacenter> your Proxmox host > virtual machine >Cloud-Init:User- create user for this virtual machinePassword- set user password for this virtual machineSSH public key- load SSH public key for SSH login to this virtual machineIP Config (net0)- set IPv4 as DHCP if you plan on using DHCP for this virtual machine or enter static IP address- in other fields leave default values
You can change above CloudInit values at any time and they will be included at the next virtual machine reboot. If you resize virtual machine disk size, it will be expanded in virtual machine at the next reboot.
Cloning virtual machine
Tip
If you plan to clone virtual machine in Proxmox that was created with cloud image it is best to clone it before first start. Otherwise if you run this VM, cloud-init will set some settings that are only set on first boot. This can result in the cloned machine receiving the same IP address from the DHCP server as the base virtual machine.
First run of Debian virtual machine
Login
Start your virtual machine in Proxmox. If everything was configured correctly you should see login screen in virtual machine Console:
Datacenter> your Proxmox host > virtual machine >Console
Enter credentials that you configured in CloudInit to log in.
Note
By default Proxmox CloudInit configure sudo command in virtual machine to don't require entering a password.
This configuration is read from read-only file: /etc/sudoers.d/90-cloud-init-users.
Check assigned IP
Check if IP is assigned by running command:
$ ip a
Other actions
With the virtual machine up and running you need to perform other typical post install actions such as:
- Set timezone
- Install
qemu-guest-agent - Create swapfile
- Create other users