This is an old revision of the document!


Building OpenWrt ON OpenWrt

Under Construction - until this tag is removed, it is better to follow the instructions on the forum.

The intention in the past hadn't been to make OpenWrt self hosting. However with only a very few additions it can be. This is still experimental and requires workarounds for bugs in perl, llvm, and OpenWrt itself. However it is eminently doable.

Why Build OpenWrt on OpenWrt?

  1. Becoming self-hosting is an important milestone for any OS
  2. It makes building OpenWrt more accessible for those with less resources.
  3. Only building on a mono-culture (x86-based full blown Linux systems) lets a lot of bugs slide under the radar. Building on a different system can (and did) expose a lot of issues that would inevitably crop up later
  4. For the educational value and bragging rights of knowing that your device's OS was built on your device.

This has so far been tested on armv7l and aarch64 devices, but will likely work on most if not all supported OpenWrt architectures. However the device's hardware does need to meet some minimum requirements:

  • 1GHz or faster CPU, multi-core is an asset.
  • 512MiB of physical RAM per core you intend to use in the build for 32-bit devices. For 64-bit devices you need double this.1
  • 2GiB of swap space. This should be on a physical hard drive, or a high quality external device (meaning not the device's internal eMMC).2
  • 1GiB of storage space on your root device for all the OpenWrt packages you will need.
  • ~26GiB of storage space for the build

Note1: The initial toolchain build (especially of llvm-bpf) is quite RAM-hungry. The given memory requirements should be considered a minimum if you are building your own llvm-bpf. If you are able to use a pre-built llvm-bpf, then you can get away with less RAM-per-used-core

Note2: Your swap space (and to a lesser extent, the storage space for the build itself) should be on a physical hard drive, or on a high quality solid state (USB, SSD) storage device. Certain steps in the process can be somewhat heavy on the swap. With a large, A good quality storage device will handle the wear better. Also, the larger your storage device is the more the wear will be spread.

First of all you need a whole lot of OpenWrt's own packages:

  • The development tools themselves:
    opkg install pkg-config make gcc diffutils autoconf automake check git git-http patch libtool-bin
  • Miscelaneous tools used in the build system:
    opkg install grep rsync tar python3 getopt procps-ng-ps gawk sed xz unzip gzip bzip2 flock wget-ssl
  • Perl3 and Python:
    opkg install perl perlbase-findbin perlbase-pod perlbase-storable perlbase-feature perlbase-b python3
  • A bunch of coreutils, since busybox versions aren't good enough in some cases, or aren't there:
    opkg install coreutils-nohup coreutils-install coreutils-sort coreutils-ls coreutils-realpath coreutils-stat coreutils-nproc coreutils-od coreutils-mkdir coreutils-date coreutils-comm coreutils-printf coreutils-ln coreutils-cp coreutils-split coreutils-csplit coreutils-cksum coreutils-expr coreutils-tr coreutils-test coreutils-uniq
  • A few libraries:
    opkg install libncurses-dev zlib-dev musl-fts
    ln -s libncursesw.a /usr/lib/libncurses.a
  • Some good-to-have packages to make life easier (instructions below will assume you have these):
    opkg install joe joe-extras bash htop whereis less file findutils findutils-locate chattr lsattr xxd

Note3: The test systems this was performed on had quite a bit of perl pre-installed, so there may be more perl packages required.

Before we can go further, we have our first bug workaround:

OpenWrt Bug: OpenWrt doesn't put execute permissions on the scripts for the automake, autoconf, and libtool packages. This prevents a lot of build systems (including OpenWrt's own) from working correctly. To fix:
chmod +x /usr/share/automake-1.16;chmod -x /usr/share/automake-1.16/COPYING /usr/share/automake-1.16/INSTALL
chmod +x /usr/share/autoconf/Autom4te/*
chmod +x /usr/share/libtool/build-aux/*

Now we can install the four dev libraries that OpenWrt doesn't support. Two of them are included in OpenWrt, just as a non-dev libraries. However, by default OpenWrt stripgs them (using sstrip) in such a way as you can't actually compile against them. Three of these three libs are just to support GNU LIBC extensions that musl doesn't have and are required mostly for elfutils. Switch to your ~/devel folder (or wherever you're going to use to build things) and do the following:

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: 2023/02/09 15:14
  • by va1der