OpenWrt 固件本地编译指南
更新日期:2025年10月25日
简介
本文档提供了在本地环境中编译定制OpenWrt系统固件的详细步骤,包括环境准备、依赖安装、源码下载、配置定制以及编译过程。
参考资料
一、准备工具
- 虚拟机软件VMware
- Ubuntu-22.04.2系统
- SSH登录工具 finalshell
- 科学上网工具(自备)
二、环境搭建
1. 安装虚拟机
安装好虚拟机,打开软件,点击创建新的虚拟机,选择典型下一步,安装程序光盘映像,点击下一步,这过程比较简单就不多做介绍,注意网卡需要设置成桥接模式。
2. 安装Ubuntu系统
点击新建虚拟机,选择默认进行安装!
三、编译固件
注意事项
- 不要用 root 用户进行编译
- 国内用户编译前最好准备好梯子
- 默认登陆IP 192.168.1.1 密码 password
1. 安装编译依赖
1 2 3 4 5 6 7 8 9 10 11 12
| sudo apt update -y sudo apt full-upgrade -y
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \ bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib \ git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev \ libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz \ mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pyelftools \ libpython3-dev qemu-utils rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip \ vim wget xmlto xxd zlib1g-dev
|
2. 下载源代码
打开科学上网工具,最好全局!以下源码三选一下载,也可以使用其他团队的源码!
1 2 3 4 5 6 7 8 9 10 11
| git clone https://github.com/openwrt/openwrt
git clone https://github.com/coolsnowwolf/lede
git clone -b 22.03 --single-branch https://github.com/Lienol/openwrt
cd openwrt
|
如需指定openwrt版本,可以使用以下命令:
1 2 3 4 5
| git tag
git checkout v22.03.3
|
3. 添加插件或主题
打开openwrt文件夹,找到feeds.conf.default文件打开,添加到最下面!
1 2 3 4 5 6
| src-git amlogic https://github.com/ophub/luci-app-amlogic src-git alist https://github.com/sbwml/luci-app-alist src-git passwall_packages https://github.com/xiaorouji/openwrt-passwall.git;packages src-git passwall_luci https://github.com/xiaorouji/openwrt-passwall.git;luci src-git kenzo https://github.com/kenzok8/openwrt-packages src-git argonnew https://github.com/jerrykuku/luci-theme-argon.git;main
|
4. 更新源码
1 2 3 4 5
| ./scripts/feeds update -a
./scripts/feeds install -a
|
5. 定制OpenWrt系统
必须设置项目(CPU架构,镜像文件格式)
1 2 3 4
| Target System -> QEMU ARM Virtual Machine Subtarget -> QEMU ARMv8 Virtual Machine (cortex-a53) Target Profile -> Default Target Images -> tar.gz
|
必选软件包(基础依赖包,仅保证打出的包可以写入EMMC,可以在EMMC上在线升级,不包含具体的应用)
1 2 3 4 5 6 7 8 9 10 11 12 13
| Languages -> Perl -> perl-http-date -> perlbase-file -> perlbase-getopt -> perlbase-time -> perlbase-unicode -> perlbase-utf8
Utilities -> Compression -> bsdtar 或 p7zip(非官方源)、pigz -> Disc -> blkid、fdisk、lsblk、parted -> Filesystem -> attr 、btrfs-progs(Build with zstd support)、chattr、dosfstools、e2fsprogs、f2fs-tools、f2fsck、lsattr、mkf2fs、xfs-fsck、xfs-mkfs -> Shells -> bash -> gawk、getopt、losetup、tar、uuidgen
|
WiFi基础包,打出的包可支持博通SDIO无线模块
1 2 3 4 5 6 7 8 9 10 11 12 13
| Kernel modules -> Wireless Drivers -> kmod-brcmfmac(SDIO) -> kmod-brcmutil -> kmod-cfg80211 -> kmod-mac80211 -> USB Support -> kmod-usb-net-asix -> kmod-usb-net-asix-ax88179 -> kmod-usb2 -> kmod-usb3
Network -> WirelessAPD -> hostapd-common -> wpa-cli -> wpad-basic -> iw
|
注意:红色为选填,如果你需要!USB3.0转千兆网卡(型号:亚信asix-ax88179)则必选!
插件和主题,语言设置选项
根据需求设置,为了减少编译失败的概率,除了必要的晶晨插件,其他都不要安装,主题也是。可以编译成功后单独编译插件在安装。
1 2 3
| LUCI -> 2.Modules -> Translations -> Chinese simplified 简体中文 自选 -> 3.Applications -> luci-app-amlogic 晶晨插件,必选 -> 4. Themes 尽量不要安装,不然容易后台面板进不去!
|
如果需要重新配置
1 2 3
| rm -rf ./tmp && rm -rf .config make menuconfig make V=s -j$(nproc)
|
6. 下载dl库,编译固件
1 2 3 4 5
| make -j8 download V=s
make V=s -j4
|
编译失败处理
如果编译失败,可以执行以下命令:
1 2 3 4 5
| make clean
make dirclean
|
7. 下载编译压缩包
编译完成后输出路径:home/用户名/openwrt/bin/targets
四、开通SSH登录方法
1. 安装SSH服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| sudo -i
sudo apt-get update sudo apt-get upgrade
apt-get install ssh
sudo /etc/init.d/ssh start
ps -e | grep ssh
|
2. Ubuntu开通root登录SSH权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| sudo -i
passwd root
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
service sshd restart
ps -e | grep ssh
|