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.

Consult your distro for up to date instructions of the setup of either HostOS functionality.

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.

There is currently no template for OpenWrt available, so some manual steps are required.

  1. Create the VM folder manually at .local/share/lxc/<vm-name>/
  2. Download a snapshot rootfs of OpenWrt and unpack it to .local/share/lxc/<vm-name>/rootfs
  3. Create a .local/share/lxc/<vm-name>/config containing 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 = proc:mixed sys:ro cgroup:mixed
    # lan interface = veth
    # wan interface = veth = lxcbr0
    # adapt <user> and <vm-name>
    lxc.rootfs.path = dir:/home/<user>/.local/share/lxc/<vm-name>/rootfs
  4. run chmod on the rootfs folder with the id you obtained earlier
  5. run lxc-start -n <vm-name>
  6. run lxc-attach -n <vm-name>
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2019/10/04 16:30
  • by someothertime