Building OpenWRT on Ubuntu 22.04.1 LTS
Setting Up the Build Environment
Before compiling OpenWRT, we need to install the necessary development dependencies on Ubuntu 22.04.1 LTS:
sudo apt-get update
sudo apt-get install -y libncurses5-dev zlib1g-dev gawk flex patch git-core g++ subversion
Creating a Dedicated User Account
For security and best practices, it's recommended to compile OpenWRT using a non-root user account:
sudo adduser developer
Switch to the newly created user account:
sudo su - developer
Downloading OpenWRT Source Code
Navigate to the home directory and clone the OpenWRT repository:
cd ~/
git clone https://git.openwrt.org/openwrt/openwrt.git
Using Screen for Long-Runing Compilation
Since OpenWRT compilation can take several hours, it's wise to use screen to maintain the session in case of network disconncetion:
sudo apt-get install -y screen
Basic screen commands:
- Start a new session:
screen -S build_session - List active sessions:
screen -ls - Reconnect to a session:
screen -r build_session - Force reconnection:
screen -dr build_session - Detach from session: Press
Ctrl+AthenD
Inside a screen session:
- Create new window:
Ctrl+AthenC - Switch to next window:
Ctrl+AthenN - Switch to previous window:
Ctrl+AthenP - View session info:
Ctrl+Athen"
To end a screen session properly:
- Close all windows in the session or exit each one individually
- Type
exitin the last window to terminate the session
Preparing the OpenWRT Build Directory
Navigate to the OpenWRT source directory and clean previous build artifacts:
cd ~/openwrt
make clean # Remove binary files
make dirclean # Remove binaries and cross-compilation tools
make distclean # Remove all downloaded packages, configs, and feeds