A quick reference to OpenWrt
Created on: 2019-12-08
Tag: cheat_sheet
Given we have a supported hardware, installing OpenWrt is very simple. Head over to Table of Hardware and check if our hardware is supported. We can search by putting our device's Brand and Model on the white input box and pressing enter. We must make sure to match the version number. If we see our device on the list, we should also see a Device Page on the 5th column. The link on the device page would have detailed instruction on how to install OpenWrt on that device. The general steps would be:
Taking a backup of the router
Downloading the firmware
Resetting the router
Powering up the router
Connecting to the router via LAN cable
Going to the routers web management portal
Going to System Tools -> Firmware Upgrade section from the menu
Uploading the firmware
Waiting for the router to reboot
The either Telnet to 192.168.1.1 and set a root password, or browse to http://192.168.1.1 if LuCI is installed.
And we are done!
In Ubuntu 18.04, to build OpenWrt from source we need to follow this steps:
Installing the necessary packages:
sudo apt install subversion g++ zlib1g-dev build-essential git python python3 libncurses5-dev gawk gettext unzip file libssl-dev \ wget libelf-dev ecj fastjar java-propose-classpath build-essential libncursesw5-dev python unzip -y
Getting the OpenWrt source code:
git clone https://github.com/openwrt/openwrt.git
Going inside the directory and running the scripts to update and install feeds:
cd openwrt ./scripts/feeds update -a ./scripts/feeds install -a
Making the configuration:
make menuconfig
This will open a menu for us to select our router configuration. For example, if we want to build images for the "TL-WR841N v11" Wifi-Router, the options will be
Target System = Atheros AR7xxx/AR9xxx
Subtarget = Devices with small flash
Target Profile = TP-LINK TL-WR841N/ND v11
We can get most of the info in the Device Page column ofn Table of Hardware.
Building the firmware:
make
Afterwards, we can get the images in ./bin/targets/$SYSTEM/generic directory.
For convenience of not installing a lot of dependency in the system, I put together a Dockerfile for building the firmware from source. The process is similar to the Building from source.
First we need to get the OpenWrt source code:
git clone https://github.com/openwrt/openwrt.git
We need to change our directory to openwrt:
cd openwrt
Then we will open a file named Dockerfile with our favourite editor. I would be using vim:
vim Dockerfile
P.S. Enable paste mode if you are also using vim with Esc th : and type set paste
Then we will paste the following:
FROM ubuntu:18.04 RUN apt update RUN apt install subversion g++ zlib1g-dev build-essential git python python3 libncurses5-dev gawk gettext unzip file libssl-dev \ wget libelf-dev ecj fastjar java-propose-classpath build-essential libncursesw5-dev python unzip -y ARG USER_ID ARG GROUP_ID USER $USER_ID:$GROUP_ID WORKDIR /app COPY --chown=$USER_ID:$GROUP_ID . .
Building the OpenWrt Docker image:
sudo docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -t openwrt .
Running the scripts to update and install the feeds:
sudo docker run -it -v $(pwd):/app -eUSER_ID=$(id -u) -e GROUP_ID=$(id -g) openwrt ./scripts/feeds update -a sudo docker run -it -v $(pwd):/app -eUSER_ID=$(id -u) -e GROUP_ID=$(id -g) openwrt ./scripts/feeds install -a
Making the configuration is same as manual build:
sudo docker run -it -v $(pwd):/app -eUSER_ID=$(id -u) -e GROUP_ID=$(id -g) openwrt make menuconfig
This will open a menu for us to select our router configuration. For example, if we want to build images for the "TL-WR841N v11" Wifi-Router, the options will be
Target System = Atheros AR7xxx/AR9xxx
Subtarget = Devices with small flash
Target Profile = TP-LINK TL-WR841N/ND v11
We can get most of the info in the Device Page column ofn Table of Hardware.
Building the firmware:
sudo docker run -it -v $(pwd):/app -eUSER_ID=$(id -u) -e GROUP_ID=$(id -g) openwrt make
Afterwards, we can get the images in ./bin/targets/$SYSTEM/generic directory.
Warning
I just found out that LuCi is not working when build with the above two methods. I am working on how to solve this.
More resource:
dd if=orig.bin of=tplink.bin skip=257 bs=512 mtd -r write /tmp/tplink.bin firmware
testing openwrt custom build image in kvm:
docker image for playing around: https://openwrt.org/docs/guide-user/virtualization/docker_openwrt_image
docker image for building image: https://openwrt.org/docs/guide-user/virtualization/obtain.firmware.docker