请参考 借助 GitHub Actions 的 OpenWrt 在线集成自动编译
使用 Linux, BSD 或 MacOSX 系统来进行编译.
依赖软件包安装官方示例
通用的 Linux 系统
CentOS
# 某些软件包会依赖 EPEL
sudo yum install binutils bzip2 gcc gcc-c++ gawk gettext flex \
ncurses-devel zlib-devel zlib-static make patch unzip openssl-devel \
perl-ExtUtils-MakeMaker glibc glibc-devel glibc-static ncurses-libs \
sed sdcc intltool sharutils bison wget git-core xz
Debian / Ubuntu
sudo apt-get update
sudo apt-get install subversion g++ zlib1g-dev build-essential git \
python python3 python3-distutils libncurses5-dev gawk gettext unzip \
file libssl-dev wget libelf-dev ecj fastjar java-propose-classpath
推荐使用 Ubuntu 18 LTS x64
Ubuntu 18.04 LTS
sudo apt-get install subversion build-essential libncurses5-dev \
zlib1g-dev gawk git ccache gettext libssl-dev xsltproc zip
Y
确定完成sudo adduser openwrt
sudo usermod -aG sudo,adm openwrt
可参考 使用 gitee 建立 github 仓库镜像加速源码下载
git clone https://gitee.com/cheenbee/openwrt.git
cd openwrt
可以把 feeds 理解为接口:即可扩展的功能插件
./scripts/feeds update -a
./scripts/feeds install -a
src-git packages https://git.openwrt.org/feed/packages.git
src-git luci https://git.openwrt.org/project/luci.git
src-git routing https://git.openwrt.org/feed/routing.git
src-git telephony https://git.openwrt.org/feed/telephony.git
src-git freifunk https://github.com/freifunk/openwrt-packages.git
#src-git video https://github.com/openwrt/video.git
#src-git targets https://github.com/openwrt/targets.git
#src-git management https://github.com/openwrt-management/packages.git
#src-git oldpackages http://git.openwrt.org/packages.git
#src-link custom /usr/src/openwrt/custom-feed
以其中的 luci 为例:是一个现代化和模块化的网页界面功能接口,让我们可以通过网络浏览器控制路由设备.如果你想自定义界面显示,定制主题 即可.
sudo ./scripts/feeds -h
可以查看各命令的使用说明make menuconfig
这将打开编译 OpenWrt 的配置菜单,用于设置目标系统和选项.
menuconfig 拥有一个文本界面,包括处理的目标平台,要编译的软件包,要被包含进固件的软件包和一些内核设置
我这里以编译树莓派4的固件为例,从 Raspberry Pi 4 Tech Specs 可知架构为 Broadcom BCM2711 64-bit
Target System (目标系统)------> (Broadcom BCM27xx)
Subtarget (子目标)------> (BCM2711 boards (64 bit))
Target Profile (目标档案)------> (Raspberry Pi 4B)
Target Images (目标镜像格式)------> [*] ext4 [*] squashfs [*] GZip images
镜像格式不清楚的请自行搜索或保持默认即可
以X86_64为例:
Target System (目标系统)------> (x86)
Subtarget (子目标)------> (x86_64)
Target Profile (目标档案)------> (Generic x86/64)
Target Images (目标镜像格式)------> [*] ext4 [*] squashfs [*] GZip images
在执行最终的make
之前,最好先使用make download
预先获取所有依赖包的源文件
make -j8 download V=s
下载完成的依赖包源文件存放在 /openwrt/dl
目录下,如果你尝试使用多核编译OpenWrt,而且没有下载所有依赖包的源文件,那么你的编译很可能会失败.
make -j1 V=s
这个命令会自动执行以下操作:
编译完成需要一段时间,短则数个小时,长则数天,编译完成后固件输出路径: /openwrt/bin/targets/bla/bla
.
可通过-j选项启用多个进程以加速构建过程,首次编译推荐使用单进程:
make -j3
make V=s
make clean
cd openwrt
git pull
./scripts/feeds update -a && ./scripts/feeds install -a
make defconfig
make -j8 download
make -j$(($(nproc) + 1)) V=s
cd openwrt
rm -rf ./tmp && rm -rf .config
make menuconfig
make -j$(($(nproc) + 1)) V=s
使用非root用户设置配置编译
How to Add and Delete Users on Ubuntu 18.04
root用户直接使用强制不安全模式运行编译命令
sudo make -j $(($(nproc) + 1)) V=s FORCE_UNSAFE_CONFIGURE=1
sudo usermod -aG sudo,adm openwrt
Quick Image Building Guide
OpenWrt编译 – 说明
中文:如何编译自己需要的 OpenWrt 固件
安装OpenWrt(通用)
编译适用于mt7620a的OpenWrt