This is an old revision of the document!
OpenWrt in LXC containers
OpenWrt can run inside a LXC container, using the same kernel as running on the host system. This can be useful for development as well as for VM hosting.
Privileged vs Unprivileged
Consult your distro for up to date instructions of the setup of either HostOS functionality.
Basic Overview
The following gives a rough idea on how to get things up and running. Before anything, install LXC on the host machine and make sure it supports running unprivileged containers. You will likely also need bridge functionality and/or additional underlying related subsystems ( macvlan etc. ) if used.
Installing via image (amd64 only)
For the amd64 architecture only (as of June 2021), the download template allows to retrieve an OpenWrt image from the remote mirror. To create the OpenWrt container, just do:
lxc-create -n <container_name> -t download -- -d openwrt -a amd64
and spell the release you want to install when asked to. For any error related to fetching the GPG key, just export DOWNLOAD_KEYSERVER to a different key server and retry, e.g.:
export DOWNLOAD_KEYSERVER=keyserver.ubuntu.com
The container will be created according to your default LXC config files, so you may probably want to customize it further (e.g. add network interfaces or mount points) by modifying its specific config file that was generated in the previous stage (see lxc.container.conf(5) man page).
Installing via rootfs extraction
For all other architectures, some manual steps are required:
- Create the VM folder manually at
.local/share/lxc/<vm-name>/ - Download a snapshot rootfs of OpenWrt and unpack it to
.local/share/lxc/<vm-name>/rootfs - Create a
.local/share/lxc/<vm-name>/configcontaining the following content:
lxc.include = /etc/lxc/default.conf lxc.include = /usr/share/lxc/config/common.conf lxc.include = /usr/share/lxc/config/userns.conf lxc.arch = linux64 # find your ids via # cat /etc/s*id|grep $USER lxc.idmap = u 0 100000 65536 lxc.idmap = g 0 100000 65536 lxc.mount.auto = proc:mixed sys:ro cgroup:mixed # lan interface lxc.net.0.type = veth # wan interface lxc.net.1.type = veth lxc.net.1.link = lxcbr0 # adapt <user> and <vm-name> lxc.rootfs.path = dir:/home/<user>/.local/share/lxc/<vm-name>/rootfs
- run
chmodon the rootfs folder with the id you obtained earlier - run
lxc-start -n <vm-name> - run
lxc-attach -n <vm-name>