[OpenWrt-RPi4] 1. Building an OpenWrt image for the Raspberry Pi 4
Translated from the Vietnamese original; wording may still be rough. Read the original →
Goal
- Build an OpenWrt image for the Raspberry Pi 4 (
bcm2711). - Bring up the Ethernet interface so we can use SSH and SCP.
For an introduction to OpenWrt, have a look here: Introduction to OpenWrt
1. Clone the source code
We clone the source code straight from the official OpenWrt repository:
git clone https://github.com/openwrt/openwrt.git
Then check out a separate branch to work on:
cd openwrt
git checkout -b develop/pi4
2. Update feeds
Run:
./scripts/feeds update -a && ./scripts/feeds install -a
3. Add a config for the Ethernet interface
OpenWrt uses the file /etc/config/network to configure network interfaces.
In the source tree, create this file at:
cd package/base-files/files/etc
mkdir -p config
cd config
touch network
vim network
If you want the interface to be eth0 with the IP 192.168.1.42, the config looks like this:
config interface 'wan'
option device 'eth0'
option proto 'static'
option ipaddr '192.168.1.42'
option netmask '255.255.255.0'
option broadcast '192.168.1.255'Where:
- interface:
wan - device (physical interface):
eth0 - protocol:
static - IP address:
192.168.1.42 - netmask:
255.255.255.0 - broadcast:
192.168.1.255
Note: set the IP, netmask and broadcast to match your own network.
OpenWrt 21.02 and later use
option device. Older releases useoption ifname, which newer releases still accept but is deprecated.
4. Run menuconfig
From the OpenWrt root directory, run:
make menuconfig
Then select the Raspberry Pi 4 target and disable the firewall as shown in the screenshots:
- Target System:
Broadcom BCM27xx - Subtarget:
BCM2711 boards (64 bit) - Target Profile: Raspberry Pi 4B (64bit)
- The firewall is the
firewall4package under Base system; deselect it.


5. Build OpenWrt
Go back to the OpenWrt root directory:
cd <openwrt>
Then build:
make -j$(nproc)
The first build can take around 30 - 45 minutes. The actual time depends on your build machine and your network speed.
When the build finishes, the images are in:
bin/targets/bcm27xx/bcm2711/The image we need is:
openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz6. Flash the image to the SD card
6.1. Find the SD card device
Plug the SD card into your PC, then use:
lsblk
to find the device that belongs to the SD card. For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 512G 0 disk
├─nvme0n1p1
└─nvme0n1p2
sdb 8:16 1 32G 0 disk
├─sdb1
└─sdb2In this example, /dev/sdb is the whole SD card device.
Careful:
ddwrites directly to the device. Picking the wrong device can wipe data on another disk.
6.2. Decompress the OpenWrt image
The image currently looks like this:
openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gzDecompress it:
gzip -d openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
After decompressing you get:
openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img6.3. Write the image to the SD card
Use dd:
sudo dd if=openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img \
of=/dev/<device> \
bs=4M \
status=progress \
conv=fsync
For example, if the SD card is /dev/sdb:
sudo dd if=openwrt-bcm27xx-bcm2711-rpi-4-ext4-factory.img \
of=/dev/sdb \
bs=4M \
status=progress \
conv=fsync
When it finishes:
sync
7. Boot the Raspberry Pi 4
Put the SD card into the Raspberry Pi 4 and power the board on.
Once OpenWrt has booted, since we configured the Ethernet interface eth0 with the IP 192.168.1.42, we can reach the board over SSH:
ssh root@192.168.1.42
After logging in over SSH you get the OpenWrt shell:
BusyBox v1.36.1 (2024-11-16 18:57:58 UTC) built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt SNAPSHOT, r0+28105-afffcd09e5
-----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:~#Note: as the warning above says, the board has no root password yet and the firewall is disabled. Only connect it to a lab network, and set a password with
passwdright after your first SSH login.