How to Compile an OpenWRT Image Using Image Builder and Install it on Proxmox
Setting up OpenWRT on a Proxmox virtual machine provides a flexible and powerful environment for network management. This guide will walk you through compiling an OpenWRT image using the Image Builder and then installing that image on Proxmox.
Prerequisites
Before you begin, ensure that your system meets the following requirements:
- A computer with Proxmox VE installed
- Internet connection to download necessary files
- Basic familiarity with Linux terminal commands
Step 1: Installing Dependencies
We would need a Linux machine to compile OpenWRT firmware; later, we will ship it to the Proxmox machine.
Start by opening your terminal and installing the necessary packages to compile your OpenWRT image:
sudo apt install build-essential libncurses5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc wget unzip python3 -y
These packages include compilers, libraries, and utilities for the build process.
Step 2: Downloading and Preparing the Image Builder
Download the OpenWRT Image Builder from the official OpenWRT repository. This example uses the 23.05.3 release for x86_64 architectures:
wget https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/openwrt-imagebuilder-23.05.3-x86-64.Linux-x86_64.tar.xz
tar -xf openwrt-imagebuilder-23.05.3-x86-64.Linux-x86_64.tar.xz
rm openwrt-imagebuilder-23.05.3-x86-64.Linux-x86_64.tar.xz
cd openwrt-imagebuilder-23.05.3-x86-64.Linux-x86_64
Step 3: Configuring the Build
Open the configuration file to set the disk sizes for the kernel and root filesystem:
nano .config
Add the following lines to specify the partition sizes:
CONFIG_TARGET_KERNEL_PARTSIZE=16
CONFIG_TARGET_ROOTFS_PARTSIZE=256
We like to have 256MB flash storage for our OpenWRT firmware. The kernel and root filesystem sizes are set in. .config
as 16 MB and 256 MB, respectively, if you intend to have more disk space for OpenWRT on a virtual machine (VM), you'll need to adjust the partition sizes.
Step 4: Building the Image
Compile the OpenWRT image with the desired profiles and packages. This command builds an image for a generic profile and includes a wide range of useful packages:
make -j4 image PROFILE=generic PACKAGES="luci luci-ssl luci-theme-material luci-app-attendedsysupgrade luci-app-acme luci-app-samba4 luci-app-upnp luci-app-wireguard luci-app-openvpn luci-app-pbr luci-app-https-dns-proxy dnsmasq-full ipset xl2tpd nano open-vm-tools iptables-nft wget wget-ssl curl ca-certificates ca-bundle unzip kmod-nft-tproxy qemu-ga lsblk fdisk losetup resize2fs -luci-theme-bootstrap -dnsmasq"
Step 5: Setting Up Proxmox VM
With the image built, you can now set up a new VM in Proxmox:
- Download your compiled OpenWRT image and unpack it to the Proxmox host.
- Resize the image to fit the desired disk size for your VM (e.g., 1 GiB):
gunzip -d openwrt-23.05.4-x86-64-generic-ext4-combined-efi.img.gz
qemu-img resize -f raw openwrt-*.img 1G
- Create a new VM in Proxmox using the following settings:
- No installation media
- SeaBIOS
- No drives
- Do not start the VM immediately
Import the resized OpenWRT image into your new VM:
qm importdisk VMID openwrt-*.img YOUR-STORAGEID
Go to VM -> Hardware, select the disk named “Unused Disk 0”, click “Edit”, set the disk to VirtIO with “Discard” and “IO Thread” options enabled, and confirm with OK (If you are using NVME drive).
Also, don’t forget to change the boot order and put OpenWRT disk as a primary boot option.
Step 6: Finalizing the Setup
Add any required networking interfaces or other devices to your VM through the Proxmox interface. Usually, the first interface is LAN, and the second interface is WAN.
Conclusion
Once everything is set up, start your VM, and you should now have a running OpenWRT router inside your Proxmox environment. This setup allows you to manage your network flexibly and extend functionality through various OpenWRT packages.