In any Virtualization platform, OS template is a pre-configured operating system image that you can use to deploy a Virtual Machine. Templates enable you to create single or multiple Virtual Machines instances in seconds. It is always recommended to create a special template with all necessary configurations as opposed to cloning an existing Virtual Machine with application data, since it gives you clean state.

Proxmox Virtualization Environment is bundled with container based templates, additionally you can create and deploy KVM templates as of V3.x series releases. In this article we shall cover a step-by-step process of creating Ubuntu or Debian Linux operating system templates. A similar procedure can be applied for any other distribution of Linux.

For CentOS / Rocky / AlmaLinux use; Creating Rocky / AlmaLinux / CentOS OS Templates on Proxmox VE

Follow the steps covered in this article to have a working installation of Debian / Ubuntu Linux template.

1. Create VM on Proxmox VE

Login to your Proxmox VE environment and begin VM creation by right clicking on the hypervisor name > Create VM.

1

Give the VM a name, and optionally set VM ID. Choosing a higher number for the ID is better to avoid mixing it up with the other instances.

2

Under “OS” select “Do not use any media“.

3

Under “System” check “Qemu Agent“. No need to adjust other settings the default should work just fine.

4

On the “Disks” screen, delete auto-added SCSI disk 0. Confirm to delete when prompted.

5

You should get message “No Disks”. This is an intended output.

6

Set CPU cores to be used by this VM instance.

7

Set Memory for the instance. Note that the value provided is in MiB.

8

Under “Network“, select Bridge name, and uncheck firewall.

9

Finish the settings by clicking “Finish” button at the lower end of the page.

10

2. Attach Cloud-init disk

Cloud-init is used to handle the early initialization of the virtual machine instance before it boots from disk. By using cloud-init you can pre-configure user accounts, networking, ssh keys, e.t.c.

We need to assign CD-ROM drive to the instance. Right click the VM Name > Hardware > Add > CloudInit Drive

11

Choose storage to use the image.

12

Confirm CloudInit Drive is added in VM Hardware section.

13

Customize each variable in Cloud Init configurations section as you desire.

14

Example you can provide default password for the specified default user account.

15

DHCP works better for Networking since no manual IP address changes are required in the instance. You can adopt MAC based DHCP service.

16

Example of complete configurations

17

3. Download OS Images for KVM

We’ll download, customize and create disk from the default OS distribution cloud image.

Ubuntu Linux OS Images

### Ubuntu 22.04 ###
wget https://cloud-images.ubuntu.com/releases/jammy/release/ubuntu-22.04-server-cloudimg-amd64.img

### Ubuntu 20.04 ###
wget https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img

### Ubuntu 18.04 ###
wget https://cloud-images.ubuntu.com/releases/bionic/release/ubuntu-18.04-server-cloudimg-amd64.img

Debian Linux OS images

### Debian 12 ###
wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2

### Debian 11 ###
wget https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2

For Ubuntu rename the cloud images with .qcow2 extension.

### Ubuntu 22.04 ###
mv ubuntu-22.04-server-cloudimg-amd64.img ubuntu-22.04-server-cloudimg-amd64.qcow2

### Ubuntu 20.04 ###
mv ubuntu-20.04-server-cloudimg-amd64.img ubuntu-20.04-server-cloudimg-amd64.qcow2

### Ubuntu 18.04 ###
mv ubuntu-18.04-server-cloudimg-amd64.img ubuntu-18.04-server-cloudimg-amd64.qcow2

Resize the disk size for the VM to suitable default size.

### Ubuntu 22.04 Example ###
$ qemu-img resize ubuntu-22.04-server-cloudimg-amd64.qcow2 20G
Image resized.

### Debian 12 Example ###
$ qemu-img resize debian-12-generic-amd64.qcow2 20G
Image resized.

Enable console for the virtual machine. Replace 777 with correct VM ID.

$ qm set 777 --serial0 socket --vga serial0
update VM 777: -serial0 socket -vga serial0

4. Import created disk into VM default boot disk

The syntax of importing disk into a Virtual Machine is;

qm importdisk <vm_id> <image> <storage_name>

First list instances and storage domains in your Proxmox server run:

root@Proxmox-VE ~ # qm list
      VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID
       777 Ubuntu-22.04-Template stopped    2048               0.00 0

root@Proxmox-VE ~ # pvesm status
Name         Type     Status           Total            Used       Available        %
local         dir     active       492392868        11379732       481013136    2.31%

Importing disk for our VM with ID 777, we’ll use:

$ qm importdisk 777 ubuntu-22.04-server-cloudimg-amd64.qcow2 local
...
transferred 17.0 GiB of 20.0 GiB (84.89%)
transferred 17.2 GiB of 20.0 GiB (86.14%)
transferred 17.5 GiB of 20.0 GiB (87.39%)
transferred 17.7 GiB of 20.0 GiB (88.64%)
transferred 18.0 GiB of 20.0 GiB (89.89%)
transferred 18.2 GiB of 20.0 GiB (91.13%)
transferred 18.5 GiB of 20.0 GiB (92.38%)
transferred 18.7 GiB of 20.0 GiB (93.63%)
transferred 19.0 GiB of 20.0 GiB (94.88%)
transferred 19.2 GiB of 20.0 GiB (96.13%)
transferred 19.5 GiB of 20.0 GiB (97.38%)
transferred 19.7 GiB of 20.0 GiB (98.62%)
transferred 20.0 GiB of 20.0 GiB (99.87%)
transferred 20.0 GiB of 20.0 GiB (100.00%)
transferred 20.0 GiB of 20.0 GiB (100.00%)
Successfully imported disk as 'unused0:local:777/vm-777-disk-0.raw'

More information about VM settings can be checked with qm config command:

$ qm config 777
agent: 1
boot: order=ide2;net0
cipassword: **********
ciuser: ubuntu
cores: 1
ide0: local:777/vm-777-cloudinit.qcow2,media=cdrom
ide2: none,media=cdrom
ipconfig0: ip=dhcp
memory: 2048
meta: creation-qemu=7.2.0,ctime=1697459258
name: Ubuntu-22.04-Template
net0: virtio=F2:9D:7D:B1:38:EC,bridge=vmbr1,firewall=1
numa: 0
ostype: l26
scsihw: virtio-scsi-single
serial0: socket
smbios1: uuid=c32a607b-ece6-470c-b301-6f97c9de7d9f
sockets: 1
unused0: local:777/vm-777-disk-0.raw
vga: serial0
vmgenid: bff5d249-26fd-4445-a39c-4088f4fd7b10

Rescan volumes in your Proxmox server.

$ sudo qm rescan
rescan volumes...

After importing the image the disk will remain unused. Navigate to VM’s hardware section, and double click to attach it.

18

Click “Add” to attach the disk to the VM. You can check Discard to enable thin provisioning.

19

The disk should now show as being used.

20

Update VM boot order under Options > Boot order.

21

Select scsi0 to enable and drag it to position 2 after ide2.

22

The view after setting the boot order.

23

5. Prepare VM for templating

Use VM console to access the terminal. Login with the username and password provided inside cloud-init parameters / values.

Update and upgrade the OS.

sudo apt update && sudo apt upgrade -y 

Next install QEMU guest agent in the instance.

sudo apt install qemu-guest-agent

Enable qemu-guest-agent to start at system boot.

sudo systemctl enable qemu-guest-agent

Reset machine ID.

sudo su -
cat /dev/null > /etc/machine-id
cat /dev/null > /var/lib/dbus/machine-id
cat /dev/null > /var/lib/dbus/machine-id

Run Cloud Init cleaning script.

 cloud-init clean

Shutdown the instance

shutdown -h now

6. Create Virtual Machine from Template

We create a VM instance by cloning the template. There are two standard options for this.

  • Linked Clone – VM created from this requires less disk space but cannot run without access to the base VM Template
  • Full Clone – A VM created from full clone is a complete copy and is fully independent of the original VM Template, but requires the same disk space as the original.

To clone right click on the Template and choose “Clone“.

24

Select cloning mode – Full or Linked.

25

Select target storage for the VM instance and give it a name.

26

Before you start the instance, you can modify hardware and set your values for the default Cloud Init variables.

27

If all goes well the instance should be up and running in few seconds.

28

Conclusion

With the procedure given in this article you should have a running instance on Proxmox VE created from template created. You should no longer perform manual installation of Ubuntu or Debian Linux system. This saves you significant time from tedious manual OS installations.

More on Proxmox:

LEAVE A REPLY

Please enter your comment!
Please enter your name here