安装编译依赖
20.04
sudo apt update
sudo apt upgrade
sudo apt-get install build-essential ccache ecj fastjar file g++ gawk gettext git java-propose-classpath libelf-dev libncurses5-dev libncursesw5-dev libssl-dev python python2.7-dev python3 unzip wget python3-distutils python3-setuptools python3-dev rsync subversion swig time xsltproc zlib1g-dev
22.04
sudo apt update
sudo apt upgrade
sudo apt install build-essential clang flex g++ gawk gcc-multilib gettext git libncurses5-dev libssl-dev python3-distutils rsync unzip zlib1g-dev file wget
下载源代码
git clone https://github.com/immortalwrt/immortalwrt openwrt
授权
chmod -Rf 777 openwrt
进入openwrt目录
cd openwrt
添加第三方应用插件
添加下面代码复制到openwrt源码根目录 feeds.conf.default 文件
cat >> feeds.conf.default <<EOF
src-git-full kiddin9 https://github.com/kiddin9/openwrt-packages.git
src-git PassWall https://github.com/xiaorouji/openwrt-passwall
src-git Openclash https://github.com/vernesong/OpenClash
EOF
更新下载自定义源到本地,并安装自定义源包含的软件包
./scripts/feeds clean
./scripts/feeds update -a
./scripts/feeds install -a
图形化配置界面
make menuconfig
取消软件源安全验证
Global build settings取消Cryptographically signed package lists,Enable signature checking in opkg,Enable TLS certificate verification during package download
IPv6
Base systen里选择firewall或者firewall4
选上extra packages——ipv6helper
在 Network——Firewall——ip6tables 下启用 ip6tables-extra 和 ip6tables-mod-nat 项
Network——odhcp6c
Network——odhcpd-ipv6only
LuCI —> Protocols —> luci-proto-ipv6
LuCI —> Protocols —> luci-proto-ppp
添加无线网卡驱动(7921,88x2bu)
在Firmware勾选网卡(AX200,AX210,MT7921)
在Kernel modules —> Wireless Drivers/勾选网卡
Network —> WirelessAPD勾选hostapd,hostapd-common,hostapd-utils,wpa-supplicant
提取本地自定义固件和默认配置的差异
在上面本地编译时,当配置完成后光标移动到Save,回车保存后,会在源码根目录生成一个.config文件,此时运行下面命令来提取配置差异,并保存在diff.config文件中备用:
./scripts/diffconfig.sh > diffconfig
设置路由器默认的登录地址
设置默认IP为10.0.0.1
sed -i 's/192.168.1.1/10.0.0.1/g' package/base-files/files/bin/config_generate
编译显卡驱动
make kernel_menuconfig
Device Drivers —> Graphics support勾选Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) —>出现子菜单,然后勾选Intel 8xx/9xx/G3x/G4x/HD Graphics
下载 dl 库(-j 后面是线程数,第一次编译推荐用单线程,线程数查询nproc;)
make download -j8
执行过make download后在源码根目录会生成dl文件夹,该文件夹可备份以节省下次编译的下载时间
开始交叉编译
make -j $(($(nproc)+1)) || make -j1 || make -j1 V=s
同配置二次编译升级
cd openwrt
git pull
./scripts/feeds update -a
./scripts/feeds install -a
make defconfig
make download -j8
如果需要删除后重新配置
rm -rf ./tmp && rm -rf .config
make menuconfig
编译完成后输出路径:bin/targets