Have you ever wondered how to create your own images for LXC and then integrate them into Proxmox? Although I’ve been working with LXC for some time, I never really got around to creating my own image. Curious, I went on a quest and stumbled upon Distrobuilder – a tool for creating images for LXC and LXD, written in Go. (The tool can also create VM images, but I haven’t tried that yet.)
The installation documentation is quite comprehensive, so I won’t delve into it here. Just note that at least Golang 1.21 is required. I initially ran into problems because my Golang version was still at 1.20.
Next, I grabbed the templates from the template directory. I was particularly interested in the OpenWrt template.
In the template directory, I then executed the following command:
distrobuilder build-lxc images/openwrt.yaml -o image.variant=default -o image.release=23.05
This command creates a rootfs.tar.xz
and metadata.tar.xz
. The rootfs.tar.xz
can then be copied to the Proxmox server using scp
or rsync
.
It took me a while to understand that the rootfs.tar.xz
is sufficient to create a container.
I thought I still needed to create a separate image.
But that’s not the case.
Proxmox offers the ability to create a container directly from a rootfs.tar.xz
.
With the following command, I created the container:
pct create 107 ./rootfs.tar.xz --unprivileged 1 --ostype unmanaged --hostname openwrt -net0 name=eth0 -net1 name=eth1 --storage local-lvm
After some settings adjustments to the network interfaces, the container was ready to go and could be started.
Before starting with the creation of the VM, the packages btrfs-progs
and qemu-utils
need to be installed on Debian:
apt install btrfs-progs qemu-utils
In the template directory, I then executed the following command:
sudo /home/rar/go/bin/distrobuilder build-incus --vm ubuntu.yaml -o image.release=jammy
This command generates the files: disk.qcow2
and incus.tar.xz
.
The file disk.qcow2
can then be copied to the Proxmox server using scp
or rsync
.
qm create 390 qm importdisk 390 ubuntu.qcow2 local-lvm -format qcow2
It is important to add the hard drive to the system (Hardware
-> Edit
-> Add
) and to use UEFI:
Furthermore, the boot order must be set in Options
:
After that, the VM starts as expected:
An OpenWrt VM can be created with the following command:
distrobuilder build-incus --vm images/openwrt.yaml -o image.release=23.05
Unfortunately, there is an issue with the EFI partition in distrobuilder.
Overall, I find Distrobuilder to be an excellent tool for creating images for LXC. It’s easy to use and allowed me to quickly and effortlessly create my own OpenWrt image and integrate it into Proxmox.