Best practice and recommendations for building VM templates

May 1, 2022
66
9
13
Stockholm, Sweden
Good afternoon

I have been using Packer to build images/templates for Ubuntu and now I am looking to expand it to Debian, Rocky Linux, FreeBSD and OpenBSD.
It feels like I can't be the first person doing this and does this forum have any good documentation, links, examples and experience to share?

The current issue I have with Ubuntu is at the first time starting the image to expand the root partition and it feels like other could have had these issues.

I will gladly share my scripts if anyone if interested.
 
Hi @Veidit,


Packer is a great tool to continue building your templates - there’s plenty of documentation available, so no need to reinvent the wheel.

I’m not entirely clear on what issue you’re facing with expanding the root disk. Packer should handle that automatically, and if you’re expanding the disk further after cloning the template, CloudInit should take care of that as well.

Cheers


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Hi @Veidit,


Packer is a great tool to continue building your templates - there’s plenty of documentation available, so no need to reinvent the wheel.

I’m not entirely clear on what issue you’re facing with expanding the root disk. Packer should handle that automatically, and if you’re expanding the disk further after cloning the template, CloudInit should take care of that as well.

Cheers


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

The issue I have is that I create a VM from a template and if I choose to expand the disk before I start the VM.
I am not sure if I handle it via user-data from cloud init but it looks like this:

Code:
  storage:
    layout:
      name: lvm
      sizing-policy: all
 
The issue I have is that I create a VM from a template and if I choose to expand the disk before I start the VM.
I am not sure if I handle it via user-data from cloud init but it looks like this:
Its not clear to me what the issue is. The snippet you posted applies to new empty disk. Your original post was about existing root partition. That would be handled by something like this:
Code:
#cloud-config
growpart:
  mode: auto
  devices: ['/']
  ignore_growroot_disabled: false

# Optional: resize the filesystem after partition grows
runcmd:
  - resize2fs /dev/sda1  # adjust device name as needed

There are multiple variations here , they depend on what your image looks like and what exactly you want to do. You can do most of the prep-work in Packer. You can also do everything from Cloud-Init.

That said, none of this is PVE specific and falls outside of the topic of the forum "Proxmox VE: Installation and configuration"



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox