Using OpenWrt on a PC for building images

Can I use a PC based version of OpenWrt as a build system for router images?

No, OpenWrt is not self-hosting, you need to use a general purpose linux distribution for building OpenWrt (Debian, Fedora, arch, gentoo, OpenSuSE, Mageia, Ubuntu, whatever you like).

2 Likes

I thought OpenWrt was a stripped down version of Linux, so am not sure what self-hosting means. Presumably the OpenWrt toolchain is available on OpenWrt...

I would prefer FreeBSD. I did manage to put together a build system at one point, but never tried building an OpenWrt image.

Unfortunately FreeBSD is no longer mentioned as one of the OSes capable of building images, so I don't know if anything has changed or if no one has tried using it.

I'll see if I can find any posts about it in the archives.

Self-hosting means the ability to bootstrap itself - to build itself from the running system. A general purpose distribution can do that (at least the later, bootstrapping from zero varies and might need more hand-holding), OpenWrt can't. This ability would require a lot more focus on shipping a on-device toolchain and -dev packages, both of which are unnecessary for OpenWrt's primary usage scenario (routing) and would require considerably more space (repo indices, package relations, package/ repo size, developer time - and a better package manager), for (close to-) zero gain (you wouldn't want to compile anything on the average plastic router, nor should you even try (for security reasons)).

Yes, there is an installable gcc package in OpenWrt, but pretty much everything beyond that is missing - you can probably compile a simple ANSI-/ ISO C program on your device, but anything requiring linking to libraries will fail (missing headers, -dev package and much more). It's a router, not a buildhost.

3 Likes

I was used Raspberry 4B, installed ubuntu first, then installed OpenWrt source code, then build OpenWrt for Raspberry 4B successfully. Only problem is the first build takes several hours.

1 Like

If you leave it running overnight it does really matter how long it takes.

For those that don't want to dual-boot Linux and Windows on a machine - WSL2 is great for this use case.

However, OpenWRT will complain about the default PATH setting in WSL2, you need to run the following script to remove "bad" elements from your PATH variable:

#!/bin/sh
PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')