OpenWrt 编译过程
每次编译 OpenWrt 的步骤都大同小异,以下为基本步骤。
安装编译依赖
- 首先装好 Linux 系统,推荐 Debian 11 或 Ubuntu LTS
- 以下所有步骤,使用非 root 用户,安装编译依赖
1
2
3
4
5
6
7
8
9sudo 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
拉取指定分支
$ git clone -b openwrt-21.02 https://github.com/immortalwrt/immortalwrt
添加其它插件源
在拉取的分支源码根目录 feeds.conf.default 文件中添加以下两行:
1 | src-git kenzo https://github.com/kenzok8/openwrt-packages |
更改配置
更改默认 IP
OpenWrt 默认 IP 为 192.168.1.1,如需更改为 192.168.50.20,运行如下命令:
$ sed -i 's/192.168.1.1/192.168.50.20/g' package/base-files/files/bin/config_generate
更新安装 feeds 源中的软件包
feeds 是扩展的软件包,独立于 OpenWrt 源码之外,所以需要单独进行拉取和更新。
1 | $ ./scripts/feeds update -a |
调整 OpenWrt 系统组件
$ make menuconfig
将弹出菜单,选择所需要的组件。我个人所调整的组件如下:
架构
- Target System –> x86
- Subtarget –> x86_64
- Target Profile –> Generic x86/64
- Target Image
squashfs
Build GRUB EFI image
Use Console Terminal
Build VMware image files
Root filesystem partition size –> 800
LuCI
Themes
- luci-theme-argonv3
- luci-theme-bootstrap
- luci-theme-netgearv2
Applications
- luci-app-accesscontrol
- luci-app-adbyby-plus
- luci-app-adguardhome
Include Binary File
- luci-app-argon-config
- luci-app-autoreboot
luci-app-baidupcs-web- luci-app-cifs-mount
- luci-app-ddns
- luci-app-diskman
Include btrfs-progs
Include lsblk - luci-app-filetransfer
- luci-app-firewall
- luci-app-frpc
- luci-app-frps
- luci-app-gowebdav
- luci-app-haproxy-tcp
- luci-app-hd-idle
- luci-app-ipsec-vpnd
- luci-app-openclash
- luci-app-opkg
- luci-app-passwall
- luci-app-ramfree
- luci-app-rclone
Include rclone-webui
Include rclone-ng - luci-app-samba4
- luci-app-smartdns
- luci-app-softethervpn
- luci-app-ssr-plus
- luci-app-ttyd
- luci-app-turboacc
Include Flow Offload
Include BBR CCA - luci-app-unblockmusic
UnblockNeteaseMusic Golang Version
UnblockNeteaseMusic NodeJS Version - luci-app-upnp
- luci-app-usb-printer
- luci-app-uugamebooster
luci-app-v2ray-server- luci-app-vlmcsd
- luci-app-vsftpd
- luci-app-watchcat
- luci-app-webadmin
- luci-app-wireguard
- luci-app-wol
- luci-app-xlnetacc
- luci-app-zerotier
Network
Firewall > ip6tables > ip6tables-extra ip6tables-mod-nat
IP Addresses and Names
- ddns-scripts_aliyun
- v2ray-geoip
- v2ray-geosite
Utilities
Disc
- cfdisk
Extra package
- autosamba
- ipv6helper
预下载编译所需的软件包
$ make download -j8 V=s
开始编译
如果使用 WSL/WSL2 进行编译,由于 WSL 的 PATH 中包含带有空格的 Windows 路径,有可能会导致编译失败,请在 make
前面加上
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ make -j1 V=s
再次编译
更新系统软件包及 OpenWrt 源码
$ sudo apt update
$ git pull
更新并安装 feeds 源中的软件包源码
$ ./scripts/feeds update -a && ./scripts/feeds install -a
更新配置文件
$ make defconfig
编译
与初次编译指令相同
$ make -j1 V=s
$ make V=s -j$(nproc)
编译固件位置
在资源管理器地址栏输入 \wsl$ 即可访问 WSL 下的文件。以 x86_64 平台为例子,固件所在路径为:
\\wsl$\WSL名称\home\用户名\lede\bin\targets\x86\64