Here is an example to create a Ubuntu 22 cloud image to use in ProxMox

One more thing to do to proxmox or where ever you want to download the image

apt install libguestfs-tools -y

That was a neat trick I saw on Create ProxMox Ubuntu Image that I integrated into my process.

The new version expects the following things in environment variables

  • SOME_PASSWORD - Used for user login
  • ST_VOL - c-vm in my case, but where do you want the image to be stored in proxmox aka local-lvm???
  • PUB_SSHKEY - the public ssh key path that will be used by ssh to allow access to vm
  • VM_ID - here I am using 9120
cd ~
qm destroy $VM_ID
rm ubuntu-amd64.qcow2
# Get the latest image from ubuntu...
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img -O ubuntu-amd64.qcow2
# Currently this is causing problems with system id and system does not work well once this is ran 
# blacklist with /etc/apt/apt.conf.d/50unattended-upgrades
#linux-headers
#inux-image
#linux-generic
#linux-modules

virt-customize -a ubuntu-amd64.qcow2 \
 --install qemu-guest-agent \
--truncate /etc/machine-id 


# create vm called ubuntu-22-cloud with 2048 memory and net0 at vmbr0
qm create $VM_ID --name ubuntu-22-cloud --cpu host --machine q35 --memory 2048 --cores 4 --net0 virtio,bridge=vmbr0 --agent enabled=1,fstrim_cloned_disks=1,type=virtio

# now make into a proxmox compatible image file.
qm importdisk $VM_ID ubuntu-amd64.qcow2 $ST_VOL -format qcow2

# now attach it to scsi interface as a disk
qm set $VM_ID --scsihw virtio-scsi-pci --scsi0 $ST_VOL:vm-$VM_ID-disk-0

# create the boot image disk
qm set $VM_ID --ide2 $ST_VOL:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0 

#Oh, resize the disk from 2G to 30G 
qm resize $VM_ID scsi0 +28G

# set dhcp or static
qm set $VM_ID --ipconfig0 ip=dhcp
##qm set 9120 --ipconfig0 ip=10.10.10.222/24,gw=10.10.10.1

# Copy over the public ssh key
qm set $VM_ID --sshkey $PUB_SSHKEY

# Set Ubuntu password
qm set $VM_ID --cipassword $SOME_PASSWORD
#qm set <vmid> --cicustom "user=local:snippets/user-data.yml"

# done now dump the user
qm cloudinit dump $VM_ID user

qm template $VM_ID

rm ubuntu-amd64.qcow2

Leave a Reply

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