Post

Proxmox 101: Create Virtual Machine and Template from Cloud Image

Create VM for Generating Template

  1. Click Create VM to start
  2. Insert PVE Node, VM Name, VM ID, check if we want to start the VM right after creation, and optional parameter for start and shutdown command

  3. Choose do not use any media because we will import it using cloud image disk later

  4. Select driver for graphic card, SCSI controller, and machine type that we want to use. We can also check qemu guest agent to add some additional features betweeen VM and Proxmox later

  5. This is where its differ from how we create VM using ISO file. We don’t need to add new disk because we will use our imported cloud image disk later. So remove the SCSI disk and leave it blank

  6. Next we can configure how much vCPU we want for VM to use. We can also configure some optional parameter related to CPU like NUMA, AES encryption, and many more

  7. Next is to configure how much memory (RAM) we want to use for our VM.

  8. Last step, we can configure network device for our VM here

    Make sure to not overestimated CPU and memory to avoid high resource usage and resource fighting between VM and Host

  9. Overview before we start the VM creation. If you are sure about your choice and configuration, start create VM by clicking finish

  10. Next step is importing cloud image file to Proxmox VE disk storage and use it as our VM boot disk

Import Cloud Image Disk File into VM

For this step, we need access into Proxmox host either by using SSH or via Console menu on Proxmox VE

  1. Download cloud-image file and resize it to give more space for our VM

    1
    2
    3
    
     wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img -O /tmp/ubuntu-22.04-cloud.img
    
     qemu-img resize /tmp/ubuntu-22.04-cloud.img 20G
    
  2. Check our disk storage format

    • If you use directory based storage like local directory or NFS, use qcow2 format when importing it to utilize the live snapshot feature.
    • If you use block based storage lika ceph, lvm, or zfs, by default they will use RAW format.
    • Use pvesm status to check what is your datastore format.
    1
    
     pvesm status
    

    As you can see above we have zfspool for our disk storage so we will use RAW format.

  3. Import cloud image file to disk storage

    1
    2
    3
    4
    5
    
     # For RAW format
     qm importdisk 1000 /tmp/ubuntu-22.04-cloud.img local-zfs_disks
    
     # For qcow2 format
     qm importdisk 1000 /tmp/ubuntu-22.04-cloud.img local-zfs_disks --format qcow2
    

    We can check our disk images using command:

    1
    
     pvesm list local-zfs_disks
    

Edit VM Hardware for Template

  1. After successfully import the cloud image, it will shown as unused disk on our VM. Double click it to edit. Check discard to use thin provisioning and check SSD emulation for better performance if your disk storage is using SSD

  2. From the same Hardware menu, add CloudInit driver to our disk storage with IDE bus driver

  3. Move to CloudInit menu, double click each variabel and give it the value you need. For example, below is my CloudInit value:

    VariabelsValues
    Userubuntu
    Passwordsecretpassword
    DNS domainfebryandana.xyz
    DNS servers1.1.1.1
    SSH public keyroot@labcx1 and root@fb-pve
    Upgrade packagesYes
    IP Configip=dhcp
  4. Then click Regenerate Image to refresh our CloudInit image

  5. Next we modify our boot order and choose scsi as our second boot device, below ide2 (cd-rom)

Start and Configure VM Before Convert It as Template

We need to configure some things before converting our VM into template. We cannot revert the VM after convert it to template so be careful.

  1. Power On VM and open console

  2. Upgrade system packages

    1
    2
    
     sudo -i
     apt update && apt upgrade -y
    
  3. Install qemu-guest-agent and other packages that you need

    1
    
     apt install qemu-guest-agent net-tools tree
    
  4. Enable qemu-guest-agent

    1
    
     systemctl start qemu-guest-agent
    
  5. Reset machine-id

    1
    2
    
     cat /dev/null > /etc/machine-id
     cat /dev/null > /var/lib/dbus/machine-id
    
  6. Clean CloudInit configuration

    1
    
     cloud-init clean
    
  7. Shutdown VM

    1
    
     shutdown -h now
    

Convert VM to Template

This action cannot be reverted. Make sure you have done all steps above before proceed

Right click on VM ID, then choose Convert to template:

Clone Template to Create New VM

  1. Right click on VM template, then choose Clone

  2. Fill in additional information, then click Clone

  3. After VM creation is complete, start the VM and check if our template and CloudInit config running properly

    You can see that our hostname and IP address changed properly from our template. The SSH public key also injected so it’s mean that our CloudInit is working.

    Because we install qemu-guest-agent earlier, we can also check our VM’s IP Address directly from Proxmox VE dashboard without needing to connect to VM console. This is good if we want to access the VM from SSH without needing to use Console.

And there we have it! An Ubuntu 22.04 server template for our next VM. With this template, we don’t need to dwell in OS installation everytime we want to create new VMs.

I hope you find this guide helpful and see you on another time.

References

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.