Building a Kernel Module for OpenWRT: My Unexpected Deep Dive
A few days ago, I found myself needing a very specific WiFi driver (kmod-mt76x2
) for OpenWRT 23. Instead of hunting for precompiled .ipk
packages or praying for a miracle in some forgotten GitHub issue, I rolled up my sleeves and decided to build the module myself — the hard way. Here's how it went.
☁️ My Setup
- 2 CPU cores
- 4 GB RAM
- About 30 GB of storage
- Host Kernel:
6.1.0-18-amd64
- OpenWRT target kernel:
6.6.73
🔄 Step-by-Step Overview
1. Cloning the OpenWRT Source
git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
I stuck with the openwrt-23.05
branch to match my router firmware.
2. Installing the Essentials
sudo apt update
sudo apt install build-essential clang flex bison g++ gawk gcc-multilib \
gettext git libncurses-dev libssl-dev python3-distutils rsync unzip \
zlib1g-dev file wget python3 python3-pip python3-setuptools
Optional: ccache
and ninja-build
for faster builds.
3. Configuring the Build
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
In the menu:
- Target system: match your OpenWRT device
- Package → Kernel Modules → Wireless Drivers → ✅
kmod-mt76x2
(M
or*
)
Then save the config and run:
make -j1 V=s
Note: I used -j1
to avoid RAM overload on my small VM.
4. Running Into Errors? Yup.
Midway through, tools/tar
failed because I was running as root. Solution?
export FORCE_UNSAFE_CONFIGURE=1
make -j1 V=s
Patience was key here. CMake alone took over 40 minutes. But it was satisfying watching those lines tick up: [512/862]
and counting.
📦 So Where's the .ko
File?
Once the build finishes, the kernel object file (mt76x2e.ko
) should be inside:
build_dir/target-*/linux-*/mt76x2*/mt76x2e.ko
From here, I can:
- Copy it to my OpenWRT router
- Use
insmod
to load it - Or package it as a
.ipk
for deployment
More on that in Part 2 😉
🤔 Why I Did This
Honestly, it was part curiosity, part necessity. I didn't want to rely on outdated binaries or third-party repos. And now, I've got a custom kernel module, fully aligned to my current kernel version.
Also? It's fun. Frustrating at times, but fun.
💬 Lessons Learned
- 2 cores and 4 GB RAM can build OpenWRT — just bring coffee.
- Always check your kernel versions between host and target.
- Don't run
configure
scripts as root unless you really have to. - This whole thing makes you appreciate package maintainers so much more.
Got questions about building OpenWRT packages or kernel modules? Drop me a message. Happy to share notes!
Member discussion