Create Openwrt Vm

Creating OpenWrt VM #

Overview #

For more generic instructions on creating an OpenWrt system in a QEMU VM see:

Here I describe a more detailed VM creation process on Proxmox VE. For the most part it repeats this guide with minor differences.

Tested with OpenWrt versions:

  • 21.03.0
  • 22.03.*, 22.05.*
  • 24.10.*

Proxmox clusters:

  • Proxmox VE 7
  • Proxmox VE 8

Template Image #

First, we need to download the current release from the OpenWrt releases website. The current version is 24.10.1, and based on the past release history, we can expect a major release roughly every 1-1.5 years.

Unpack the .gz file (to keep the original, run gunzip on a copy):

gunzip openwrt-24.10.1-x86-64-generic-ext4-combined.img.gz

Resize the image, usually 1G is plenty for an OpenWrt VM:

qemu-img resize -f raw openwrt-24.10.1-x86-64-generic-ext4-combined.img 1G

We still need to resize the GPT partition and the filesystem. To do it before importing the image into the VM (i.e., in advance) we can mount the image into another linux system and do the adjustments. The advantages of this in advance is that we would have to take care of this only once and the template image would contain the adjusted filesystem that can be used immediately. However, it also requires having another Linux VM ready and the need to copy the image into that VM and back into the Proxmox VE node.

Note If the backing storage for the VM drive is directory-based, convering the raw image to a sparse qemu image, can reduce storage usage.

We can keep this image as a template for new VMs.

Create a Proxmox VM #

Create a new Proxmox VM with:

  • no installation media
  • if UEFI-boot is needed adjust the BIOS option (in this case, we must use the EFI version of OpenWrt)
  • select “Qemu Agent” if necessary
  • remove the default boot drive
  • OpenWrt does not use much RAM, so memory can be reduced to 512MiB

Import the resized OpenWrt image as the boot drive to the newly created VM:

qm disk import {VMID} openwrt-24.10.1-x86-64-generic-ext4-combined-resized-1g.img local-lvm

where

  • {VMID} is the numeric ID of the created VM,
  • local-lvm is the name of the storage to put write drive image to, if the cluster have already been configured to use a different storage for VM drives, make sure to replace this with the correct storage.

After this step, we can find the new drive in the Proxmox web UI, but it will likely be in an “unused drive” state. Select the new drive, click on the “edit” button, then click “Add.”

Adjust the boot order.

Also, usually, we need to add the second network interface attached to a different bridge (or a vlan tag on a vlan-aware bridge). One will be used for LAN, and the other for WAN.

Note If we do not add the second network interface before the first boot, the WAN interface will not be configured. So, when adding the second network interface post install, we need to manually configure it in /etc/config/network (see below).

OpenWrt instance acts as a router on the net0 interface (its br-lan would be attached to this interface). By default, the LAN CIDR is 192.168.1.1/24.

Start the VM.

The management console will be available on interface 0 (net0).

Configure the WAN Interface #

Use the Proxmox console or SSH into the OpenWrt router from another machine which is a DHCP client on the subnet managed by this router instance.

Add the following configuration to /etc/config/network:

config interface 'wan'
	option device 'eth1'
	option proto 'dhcp'

We can use the old vi to do the initial config, because neither nano nor vim are installed by default (and unfortunately at this stage, we do not have internet to install new packages on this node). The preinstalled less also lacks the searching functionality (so, we’d have to install the full version of that as well).

Restart the VM.

Alternatively, restart the network service.

Warning When the router shell is accessed over SSH, depending on the new network configuration, the SSH connection may get interrupted upon restarting the network service.

/etc/init.d/network restart

Now, the OpenWrt instance should have access to the internet. So, we can update and install the necessary packages.

Update the list of available packages and install full versions of vim and less ():

opkg update
opkg install vim-fuller less

Now we can view and search available packages:

opkg list | less

Adjust the Filesystem #

Refs:

If we have not adjusted the filesystem after resizing the image, only the original ~100MiB space is usable at first. To fix this, we can install additional disk utilities into OpenWrt and do it within the system. Then, we can run a community script that resizes the partition with parted and then expands the filesystem with resize2fs.

# Install packages
opkg update
opkg install parted losetup resize2fs blkid
 
# Download expand-root.sh
wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"
 
# Source the script (creates /etc/uci-defaults/70-rootpt-resize and /etc/uci-defaults/80-rootpt-resize, and adds them to /etc/sysupgrade.conf so they will be re-run after a sysupgrade)
. ./expand-root.sh
 
# Resize root partition and filesystem (will resize partiton, reboot resize filesystem, and reboot again)
sh /etc/uci-defaults/70-rootpt-resize

The system has to be rebooted twice:

  • after resizing the partition
  • after resizing the filesystem

Next Steps #

The OpenWrt instance is now ready to be used. See other notes for additional customizations.