前言
- 此前一直使用Padavan老毛子固件以及别人编译好的固件,但是总有那么几款插件不合胃口,于是乎,自己动手编译,这里说明一下,我是歌华链路由器,废话不多说,开干。
一、拉取镜像
docker pull p3terx/openwrt-build-env:18.04
二、启动容器
docker run -itd \ --name ghl-openwrt-lede-build \ -h GHL-R-001 \ -p 10022:22 \ -v ~/openwrt:/home/user/openwrt \ p3terx/openwrt-build-env:18.04
三、宿主机操作
- 配置科学,否则会编译失败,如果此步骤不会操作请自行搜索解决。
# 打开.bashrc文件 vim ~/.bashrc # 将以下内容追加至.bashrc export http_proxy=http://10.211.55.2:7890;export https_proxy=http://10.211.55.2:7890; source ~/.bashrc # 如果紧临时用一次可以直接在终端输入 export http_proxy=http://10.211.55.2:7890;export https_proxy=http://10.211.55.2:7890;
- 克隆lede源码
git clone https://github.com/coolsnowwolf/lede openwrt
四、容器操作
- 进入容器:
docker exec -it ghl-openwrt-lede-build bash
- 修改文件归属用户和用户组为user:
sudo chown -hR user:user .
- 更换ubuntu源:
sudo -s sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list && sed -i s@/security.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list exit sed -i s@/mirrors.aliyun.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list
- 安装openclash需要的依赖包:
sudo apt-get update && sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3.5 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget
五、预编译
1.自定义配置
- 进入openwrt源码目录
cd openwrt
- 新增三方插件源
# 新增三方插件源 vi feeds.conf.default # 追加以下内容 src-git kenzo https://github.com/kenzok8/openwrt-packages src-git small https://github.com/kenzok8/small # :wq保存退出 # 一键添加 echo 'src-git kenzo https://github.com/kenzok8/openwrt-packages' >>feeds.conf.default echo 'src-git small https://github.com/kenzok8/small' >>feeds.conf.default
- 修改默认WEB管理地址
# 修改默认WEB管理地址 # 这里我改为 192.168.9.1 # 一键更换命令 sed -i 's/192.168.1.1/192.168.9.1/g' package/base-files/files/bin/config_generate
- 修改默认主机名称和时区
# 一键更换命令 sed -i "s/hostname='.*'/hostname='LoganJin-GeHua'/g" package/base-files/files/bin/config_generate sed -i "s/timezone='.*'/timezone='CST-8'/g" package/base-files/files/bin/config_generate sed -i "/.*ttylogin='0'.*/i\ set system.@system[-1].zonename='Asia/Shanghai'" package/base-files/files/bin/config_generate
- docker容器内配置科学
# 同上"宿主机操作-配置科学上网"方法一致
2.下载、安装feeds 源中的软件包源码
- 下载/更新
./scripts/feeds update -a # 如果报错server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none failed. # 终端输入 git config --global http.sslVerify false
feeds 是扩展的软件包,独立于 OpenWrt 源码之外,所以需要单独进行拉取和更新
- 安装 feeds 中的软件包
./scripts/feeds install -a #避免出现下面的警告 提前将mosdns_neo 改为mosdns (2022.08.13目前新版源码貌似已修复此警告) sed -i 's/mosdns.*neo/mosdns/g' feeds/kenzo/luci-app-mosdns/Makefile # 有可能会出现一大堆警告 WARNING: Makefile 'package/lean/autocore/Makefile' has a dependency on 'bc', which does not exist WARNING: Makefile 'package/lean/autocore/Makefile' has a dependency on 'lm-sensors', which does not exist WARNING: Makefile 'package/lean/autosamba/Makefile' has a dependency on 'luci-app-samba', which does not exist WARNING: Makefile 'package/lean/autosamba/Makefile' has a dependency on 'wsdd2', which does not exist WARNING: Makefile 'package/utils/busybox/Makefile' has a dependency on 'libpam', which does not exist WARNING: Makefile 'package/utils/busybox/Makefile' has a dependency on 'libpam', which does not exist WARNING: Makefile 'package/utils/busybox/Makefile' has a build dependency on 'libpam', which does not exist WARNING: Makefile 'package/lean/ddns-scripts_aliyun/Makefile' has a dependency on 'ddns-scripts', which does not exist WARNING: Makefile 'package/lean/ddns-scripts_aliyun/Makefile' has a dependency on 'wget-ssl', which does not exist WARNING: Makefile 'package/lean/ddns-scripts_dnspod/Makefile' has a dependency on 'ddns-scripts', which does not exist WARNING: Makefile 'package/lean/ddns-scripts_dnspod/Makefile' has a dependency on 'wget-ssl', which does not exist WARNING: Makefile 'package/lean/default-settings/Makefile' has a dependency on 'luci-base', which does not exist WARNING: Makefile 'package/lean/default-settings/Makefile' has a dependency on 'luci', which does not exist WARNING: Makefile 'package/qat/libs/eudev/Makefile' has a dependency on 'libkmod', which does not exist WARNING: Makefile 'package/qat/libs/eudev/Makefile' has a build dependency on 'gperf/host', which does not exist WARNING: Makefile 'package/lean/ipv6-helper/Makefile' has a dependency on 'luci-proto-ipv6', which does not exist WARNING: Makefile 'package/boot/kexec-tools/Makefile' has a dependency on 'liblzma', which does not exist WARNING: Makefile 'package/network/services/lldpd/Makefile' has a dependency on 'libnetsnmp', which does not exist WARNING: Makefile 'package/lean/mt/luci-app-mtwifi/Makefile' has a build dependency on 'luci-base/host', which does not exist WARNING: Makefile 'package/lean/mt/drivers/mt7615d/Makefile' has a dependency on 'maccalc', which does not exist WARNING: Makefile 'package/lean/n2n/Makefile' has a dependency on 'libzstd', which does not exist WARNING: Makefile 'package/lean/n2n/Makefile' has a dependency on 'libzstd', which does not exist WARNING: Makefile 'package/network/services/noddos/Makefile' has a dependency on 'libcurl', which does not exist WARNING: Makefile 'package/network/services/noddos/Makefile' has a dependency on 'libtins', which does not exist WARNING: Makefile 'package/network/services/noddos/Makefile' has a dependency on 'libyaml-cpp', which does not exist WARNING: Makefile 'package/utils/policycoreutils/Makefile' has a dependency on 'libpam', which does not exist WARNING: Makefile 'package/utils/policycoreutils/Makefile' has a dependency on 'libpam', which does not exist WARNING: Makefile 'package/utils/policycoreutils/Makefile' has a build dependency on 'libpam', which does not exist WARNING: Makefile 'package/firmware/quantenna/Makefile' has a dependency on 'libtirpc', which does not exist WARNING: Makefile 'package/firmware/quantenna/Makefile' has a build dependency on 'libtirpc', which does not exist # 如果出现上面的警告 则继续执行以下命令 ./scripts/feeds update -a ./scripts/feeds install -a
3.调整系统组件、驱动、依赖包、自定义插件等
首次编译建议只选择架构,其它都不要动,这样编译成功率会更高。如果不打算调整组件则输入
make defconfig
,它会检测编译环境并生成默认的编译配置文件。
- 调整 OpenWrt 系统组件
make menuconfig
- 选择路由器架构
Target System (MediaTek Ralink MIPS) ---> Subtarget (MT7621 based boards) ---> Target Profile (GeHua GHL-R-001) --->
- 选择主题
# LuCI ---> 4. Themes ---> <*> luci-theme-argon............................................. Argon Theme <*> luci-theme-argonne......................................... Argonne kenzo < > luci-theme-atmaterial_new........................... Atmaterial_new kenzo -*- luci-theme-bootstrap........................... Bootstrap Theme (default) < > luci-theme-ifit............................................ Ifit by kenzo (NEW) < > luci-theme-material....................................... Material Theme (NEW) < > luci-theme-mcat........................................... Mcat new kenzo (NEW) < > luci-theme-neobird......................................... Neobird Theme (NEW) <*> luci-theme-netgear......................................... Netgear Theme < > luci-theme-tomato....................................... Tomato new kenzo (NEW)
- 选择插件包
# 选择插件包 # LuCI ---> 3. Applications ---> <*> luci-app-accesscontrol................. LuCI Access Control Configuration (NEW) # 访问时间控制 <*> luci-app-adbyby-plus............................. LuCI support for Adbyby # 广告屏蔽大师Plus + [*] Include Binary File (NEW) <*> luci-app-advanced.............. LuCI Support for advanced and filebrowser # 高级文件浏览器 # luci-app-advanced 包含 luci-app-fileassistant 插件不要重复选择 <*> luci-app-advanced-reboot.................. Advanced Linksys Reboot Web UI # Linksys高级重启 <*> luci-app-aliyundrive-fuse.............. LuCI Support for aliyundrive-fuse # 阿里云盘FUSE磁盘挂载 <*> luci-app-aliyundrive-webdav.......... LuCI Support for aliyundrive-webdav # 阿里云盘 WebDAV 服务 <*> luci-app-aria2.................................... LuCI Support for Aria2 # Aria2下载工具 <*> luci-app-arpbind............................................. ARP Binding (NEW) #IP/MAC绑定 <*> luci-app-attendedsysupgrade........ LuCI support for attended sysupgrades # 固件更新升级相关 <*> luci-app-autoreboot.................... LuCI support for Scheduled Reboot (NEW) # 支持计划重启 [ ] Include Shadowsocks Libev Client (NEW) # SS Libev客户端(轻量级) [*] Include ShadowsocksR Libev Client (NEW) # SSR Libev客户端(轻量级) [ ] Include Shadowsocks Simple Obfs Plugin (NEW) # SS Simple-Obfs混淆代理(Nginx) [*] Include Xray (NEW) # Xray代理(XTLS) [ ] Include Trojan (NEW) # Trojan代理(直接模仿协议HTTPS) [] Include Socks5 Transparent Proxy (NEW) [*] Include Socks Sever (NEW) <*> luci-app-commands.............................. LuCI Shell Command Module # Shell命令模块 <*> luci-app-ddns......... LuCI Support for Dynamic DNS Client (ddns-scripts) (NEW) # 动态域名DNS(集成阿里DDNS客户端) <*> luci-app-diskman......................... Disk Manager interface for LuCI # 磁盘管理工具 [*] Include btrfs-progs (NEW) # 新型的写时复制 (COW) [*] Include lsblk (NEW) # lsblk命令 用于列出所有可用块设备的信息 [ ] Include mdadm # mdadm命令 用于创建、管理、监控RAID设备的工具 <M> luci-app-e2guardian............................ E2Guardian LuCI Interface # Web内容过滤器 <*> luci-app-easymesh.............................. LuCI Support for easymesh # 简单MESH(可有线+无线回程) # luci-app-easymesh 包含wpad 不要重复选择否则冲突 <*> luci-app-eqos...................................... EQOS - LuCI interface # 基于IP地址限速(Le库以外的插件) <M> luci-app-fileassistant.................... LuCI support for Fileassistant (NEW) # 文件管理助手(Le库以外的插件) <M> luci-app-filebrowser........................ LuCI Support for FileBrowser # 文件浏览器 <*> luci-app-filetransfer........................... LuCI page for IPK upload (NEW) # 文件传输(可web安装ipk包) -*- luci-app-firewall................ Firewall and Portforwarding application # 添加防火墙 <*> luci-app-frpc.............................................. LuCI for FRPC # 内网穿透Frp客户端 <*> luci-app-frps...................................... LuCI support for Frps # 内网穿透Frp服务端 <M> luci-app-guest-wifi.......................... LuCI support for guest-wifi <*> luci-app-hd-idle......................... Hard Disk Idle Spin-Down module # 硬盘休眠 <M> luci-app-hnet............... HNCP Homenet configuration and visualization <M> luci-app-https-dns-proxy..................... DNS Over HTTPS Proxy Web UI # 通过HTTPS代理为DNS提供Web UI <*> luci-app-mjpg-streamer........ MJPG-Streamer service configuration module # 兼容Linux-UVC的摄像头程序 <*> luci-app-mtwifi.......................... LuCI support for mt wifi driver (NEW) # MTWiFi驱动的支持 (丢弃) -*- luci-app-mwan3........ LuCI support for the MWAN3 multiwan hotplug script # MWAN3负载均衡 <*> luci-app-mwan3helper....................... LuCI support for MWAN3 Helper# MWAN3分流助手 <*> luci-app-nlbwmon...................... Netlink based bandwidth accounting (NEW) # 网络带宽监视器 <M> luci-app-ntpc.............. NTP time synchronisation configuration module # NTP时间同步服务器 <*> luci-app-openclash................................ LuCI support for clash # 运行在OpenWrt上的Clash代理客户端(Le库以外的插件) <M> luci-app-p910nd........................... p910nd - Printer server module # 打印服务器模块 <*> luci-app-passwall.............................. LuCI support for PassWall # 科学上网(Li大佬插件) <M> luci-app-pushbot................................ LuCI support for Pushbot # 全能推送(钉钉推送,企业微信推送,Bark,PushPlus推送) <M> luci-app-qbittorrent........................ LuCI support for qBittorrent [*] Include rclone-webui (NEW) # Rclone界面 [*] Include rclone-ng (another webui) (NEW) # Rclone另一个界面 <M> luci-app-samba4................. Network Shares - Samba 4 SMB/CIFS module # 网络共享(Samba4) <*> luci-app-ssr-plus (NEW) # SSR科学上网Plus+(Le大佬插件) V2ray-core Selection (Include Xray-core) ---> [*] Include ShadowsocksR Libev Client (NEW) # SSR Libev客户端(轻量级) <*> luci-app-syncdial........................... Virtual WAN config generator # 多拨虚拟网卡(原macvlan) <*> luci-app-ttyd...................................... LuCI support for ttyd # 网页终端命令行 <*> luci-app-turboacc............ LuCI support for Flow Offload / Shortcut-FE (NEW) # Turbo ACC 网络加速(支持 Fast Path 或者 硬件 NAT) [*] Include Flow Offload (NEW) [*] Include BBR CCA (NEW) # BBR拥塞控制算法提升TCP网络性能 [*] Include Pdnsd (NEW) <M> luci-app-unblockmusic......... LuCI support for Unblock NeteaseCloudMusic <M> luci-app-unblockneteasemusic........ LuCI support for UnblockNeteaseMusic <*> luci-app-upnp................. Universal Plug & Play configuration module (NEW) # 通用即插即用UPnP(端口自动转发) <M> luci-app-usb-printer........................ USB Printer Share via TCP/IP # usb 打印服务器 <*> luci-app-vlmcsd..................................... LuCI support for KMS (NEW) # KMS服务器设置 <*> luci-app-vsftpd.................................. LuCI support for VSFTPD (NEW) # FTP服务器 <M> luci-app-watchcat.............................. LuCI Support for Watchcat <M> luci-app-webadmin................................ LuCI page for Web Admin <*> luci-app-wol................................ LuCI Support for Wake-on-LAN (NEW) # WOL网络唤醒 <M> luci-app-xlnetacc.............................. LuCI Support for XLNetAcc # 迅雷快鸟 <*> luci-app-zerotier...................................... LuCI for Zerotier # ZeroTier内网穿透
- 将默认闭源Wi-Fi驱动改为开源驱动
# lean项目里默认使用的是闭源驱动,闭源驱动不支持802.11r,需要手动切换为开源驱动。 # 编译时取消 Luci => Applications =>luci-app-mtwifi Network => Wireless => mt_wifi Kernel modules => Wireless Drivers => kmod-mt7603e Kernel modules => Wireless Drivers => kmod-mt76x2e # 编译时选择 Kernelmodules => Wireless Drivers => kmod-mt7603 Kernel modules => Wireless Drivers => kmod-mt76x2 # luci-app-easymesh 包含wpad 不要重复选择否则冲突 Network => WirelessAPD => wpad
- 大容量存储设备内核支持(可选)
# Kernel modules => USB Support -*- kmod-usb-storage..................................... USB Storage support # USB大容量存储设备的内核支持 <*> kmod-usb-storage-extras.................... Extra drivers for usb-storage # 更多的USB驱动程序
- 配置可挂载的文件系统(可选)
# Kernel modules => Filesystems -*- kmod-fs-btrfs................................... BTRFS filesystem support # BTRFS 支持的内核模块 <*> kmod-fs-exfat................................... exFAT filesystem support # exFAT 内核模块 <*> kmod-fs-ext4..................................... EXT4 filesystem support # EXT4 文件系统支持的内核模块 <*> kmod-fs-ntfs..................................... NTFS filesystem support <*> kmod-fs-vfat..................................... VFAT filesystem support # VFAT 文件系统支持的内核模块 -*- kmod-fuse......................... FUSE (Filesystem in Userspace) support # 用户空间文件系统支持的内核模块
- 配置usb监控mjpg-streamer相关依赖包(可选)
# Kernel modules => USB Support <*> kmod-usb-uhci............................... Support for UHCI controllers <*> kmod-usb-ohci............................... Support for OHCI controllers # Kernel modules => Video Support <*> kmod-video-core...................................... Video4Linux support # Video4Linux 支持的内核模块 <*> kmod-video-uvc............................. USB Video Class (UVC) support # 支持 USB 视频类 (UVC) 设备的内核模块 -*- kmod-video-videobuf2....................................... videobuf2 lib # 实现三种基本媒体缓冲区类型的内核模块 # Multimedia ---> -*- mjpg-streamer.............................................. MJPG-streamer [*] Build input_uvc with libv4l2 (camera controls) < > mjpg-streamer-input-file...................... MJPG-streamer (file input) < > mjpg-streamer-input-http...................... MJPG-streamer (HTTP input) <*> mjpg-streamer-input-uvc........................ MJPG-streamer (UVC input) <*> mjpg-streamer-output-file.................... MJPG-streamer (file output) <*> mjpg-streamer-output-http.................... MJPG-streamer (HTTP output) # Utilities ---> -*- usbids....................................................... USB ID list <*> usbutils................................... USB devices listing utilities
4.预下载编译所需的软件包
- 下载
make download -j8 V=s
-j8
是指使用8个线程下载,理论上是数字越大下载越快,但似乎有个上限,实测5线程以上其实速度相差不了多少,在网络好的情况下,基本在5分钟以内能下载完。
- 检查文件完整性
find dl -size -1024c -exec ls -l {} \;
此命令可以列出下载不完整的文件(根据我多次编译的经验得出小于1k的文件属于下载不完整),如果存在这样的文件可以使用
find dl -size -1024c -exec rm -f {} \;
命令将它们删除,然后重新执行make download
下载并反复检查,确认所有文件完整可大大提高编译成功率,避免浪费时间。
- 修改ttyd默认登陆
sed -i 's/\/bin\/login/\/bin\/login -f root/' ./feeds/packages/utils/ttyd/files/ttyd.config
六、开始编译
- 编译指令
make -j1 V=s # 由于单线程太慢了 我直接使用 make -j8 V=s
-j1:使用单线程编译。新手推荐单线程编译,一是因为玄学问题可能成功率高,二是方便查看错误日志。
V=s
:输出详细日志,用于编译失败时找出错误。而且满屏代码在跑能装逼,一跑就是几个小时,装逼更持久。
- 编译过程中可能会报错
# 编译过程中可能会报错 make[3]: Entering directory '/home/user/openwrt/feeds/kenzo/luci-app-openclash' touch /home/user/openwrt/build_dir/target-mipsel_24kc_musl/luci-app-openclash/.prepared_7db2144fdc689e8ef962a79cb79bfdb6_6664517399ebbbc92a37c5bb081b5c53_check cp -fpR /home/user/openwrt/feeds/kenzo/luci-app-openclash/root /home/user/openwrt/build_dir/target-mipsel_24kc_musl/luci-app-openclash cp -fpR /home/user/openwrt/feeds/kenzo/luci-app-openclash/luasrc /home/user/openwrt/build_dir/target-mipsel_24kc_musl/luci-app-openclash po2lmo /home/user/openwrt/feeds/kenzo/luci-app-openclash/po/zh-cn/openclash.zh-cn.po /home/user/openwrt/build_dir/target-mipsel_24kc_musl/luci-app-openclash/openclash.zh-cn.lmo; bash: po2lmo: command not found Makefile:124: recipe for target '/home/user/openwrt/build_dir/target-mipsel_24kc_musl/luci-app-openclash/.prepared_7db2144fdc689e8ef962a79cb79bfdb6_6664517399ebbbc92a37c5bb081b5c53' failed make[3]: *** [/home/user/openwrt/build_dir/target-mipsel_24kc_musl/luci-app-openclash/.prepared_7db2144fdc689e8ef962a79cb79bfdb6_6664517399ebbbc92a37c5bb081b5c53] Error 127 make[3]: Leaving directory '/home/user/openwrt/feeds/kenzo/luci-app-openclash' time: package/feeds/kenzo/luci-app-openclash/compile#0.16#0.12#0.29 ERROR: package/feeds/kenzo/luci-app-openclash failed to build. package/Makefile:114: recipe for target 'package/feeds/kenzo/luci-app-openclash/compile' failed make[2]: *** [package/feeds/kenzo/luci-app-openclash/compile] Error 1 make[2]: Leaving directory '/home/user/openwrt' package/Makefile:110: recipe for target '/home/user/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile' failed make[1]: *** [/home/user/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile] Error 2 make[1]: Leaving directory '/home/user/openwrt' /home/user/openwrt/include/toplevel.mk:228: recipe for target 'world' failed make: *** [world] Error 2 user@GHL-R-001:~/openwrt$ # 缺少po2lmo # 先编译内核:make package/feeds/luci/luci-base/compile V=s # 然后再重新编译即可 make -j8 V=s
- 编译完成
# 编译完成后在下面目录 /home/user/openwrt/bin/targets/ramips/mt7621 user@GHL-R-001:~/openwrt/bin/targets/ramips/mt7621$ ls -l total 54512 -rw-r--r-- 1 user user 4561 Jul 6 21:43 config.buildinfo -rw-r--r-- 1 user user 378 Jul 6 21:43 feeds.buildinfo -rw-r--r-- 1 user user 27719026 Jul 6 22:38 openwrt-ramips-mt7621-gehua_ghl-r-001-initramfs-kernel.bin -rw-r--r-- 1 user user 28050210 Jul 6 22:38 openwrt-ramips-mt7621-gehua_ghl-r-001-squashfs-sysupgrade.bin -rw-r--r-- 1 user user 9402 Jul 6 22:38 openwrt-ramips-mt7621-gehua_ghl-r-001.manifest drwxr-xr-x 2 user user 12288 Jul 6 22:38 packages -rw-r--r-- 1 user user 615 Jul 6 22:38 sha256sums -rw-r--r-- 1 user user 16 Jul 6 21:43 version.buildinfo
终端sysupgrade刷固件
sysupgrade -F -n 固件名
# 参考:https://www.right.com.cn/forum/thread-8207921-1-1.html
结语
- 参考:https://p3terx.com/archives/openwrt-compilation-steps-and-commands.html
- 至此,所有部署frpc步骤全部完成,需要的小伙伴赶紧去尝试一下吧。
- 如部署或者其他问题欢迎去我的博客(www.loganjin.cn)留言或者微信公众号(Python技术交流圈)留言交流哦。
版权声明:如无特殊说明,文章均为本站原创,转载请注明出处
本文链接:https://www.loganjin.cn/article/ghl-openwrt/
许可协议:署名-非商业性使用 4.0 国际许可协议