找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 1386|回复: 2

ubuntu编译openwrt教程

[复制链接]
本帖最后由 alps2006 于 2022-9-30 00:29 编辑

编译环境
目前 openwrt 主要是在需要在 linux 环境下安装, 支持 ubuntu, centos, wls-ubuntu, mac 等, 但官方主要推荐基于 ubuntu 编译, 且自己也刚好有台 ubuntu 的云服务器.
主要的环境:
  • Openwrt 源码: 基于 Lean 大的源码进行编译.  https://github.com/coolsnowwolf/lede
  • 系统: Ubuntu 18.04.6 LTS
  • 磁盘空间: 根据启用的插件决定, 常规默认参数, 启用 ssr 插件 + easymesh + adblock + smartdns, 编译达到 14G+
  • 其它: 能够访问国外资源, 因为编译时部分依赖需要

安装 xray 客户端
目前我使用的是国内的腾讯云服务器, 无法访问国外的资源, 所以安装了 xray 客户端连接梯子服务器, 并在本地暴露了 http 服务端口, 使用 export proxy 在终端使用 .
主要操作:

  • 下载二制包, 我使用的是目前最新的 1.6 版本
    1. wget https://github.com/XTLS/Xray-core/releases/download/v1.6.0/Xray-linux-64.zip
    复制代码

  • 解压并运行, config 需要自行配置, 详细参考其它资源
    1. unzip Xray-linux-64.zip
    2. cd Xray-linux-64
    3. ./xray -c config.json &
    复制代码

  • 设置终端 proxy, 执行 (前提是暴露了 http 端口为 1087)
    1. export http_proxy=http://127.0.0.1:1087; export https_proxy=http://127.0.0.1:1087; export all_proxy=http://127.0.0.1:1087
    复制代码

  • 需要取消终端 proxy, 执行
    1. unset http_proxy; unset https_proxy; unset all_proxy;
    复制代码


安装依赖
编译前需要安装好编译相关的依赖库和程序, 在 ubuntu 下使用 apt-get 可以很方便的安装, 主要执行:
  1. sudo apt update -y
  2. sudo apt full-upgrade -y
  3. 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-pip libpython3-dev qemu-utils \rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
复制代码

编译
源码下载
使用 git clone 下载最新的 lean 大源码:
  1. git clone https://github.com/coolsnowwolf/ledecd lede
复制代码


添加 ssr feeds 仓库
目前最新源码默认情况未添加 ssr 的 feeds 支持, 需要自行添加, 执行:
  1. echo "src-git helloworld https://github.com/fw876/helloworld.git" >> "feeds.conf.default"
复制代码

更新及安装 feeds
  1. ./scripts/feeds update -a
复制代码

配置
在编译前需要进行配置硬件设备信息(包括硬件平台, 版本, 型号等), 以及模块插件等. 通过执行 make menuconfig 能打开参数配置界面, 下面以我 HC5962 配置说明:
  1. │ │         Target System (MediaTek Ralink MIPS)  --->             │ │
  2. │ │         Subtarget (MT7621 based boards)  --->                  │ │
  3. │ │         Target Profile (HiWiFi HC5962)  --->                   │ │
  4. │ │         Target Images  --->                                    │ │ (选择了 squashfs)
  5. │ │     [ ] Enable experimental features by default                │ │
  6. │ │         Global build settings  --->                            │ │
  7. │ │     [ ] Advanced configuration options (for developers)  ----  │ │
  8. │ │     [ ] Build the OpenWrt Image Builder                        │ │
  9. │ │     [ ] Build the OpenWrt SDK                                  │ │
  10. │ │     [ ] Package the OpenWrt-based Toolchain                    │ │
  11. │ │     [ ] Image configuration  --->                              │ │
  12. │ │         Base system  --->                                      │ │
  13. │ │         Administration  --->                                   │ │
  14. │ │         Boot Loaders  ----                                     │ │
  15. │ │         Development  --->                                      │ │
  16. │ │         Extra packages  --->                                   │ │
  17. │ │         Firmware  --->                                         │ │
  18. │ │         Fonts  --->                                            │ │
  19. │ │         Kernel  ----                                           │ │
  20. │ │         Kernel modules  --->                                   │ │
  21. │ │         Languages  --->                                        │ │
  22. │ │         Libraries  --->                                        │ │
  23. │ │         LuCI  --->                                             │ │ (二级菜单 Application 中选择了 luci-app-easymesh, adblock, 而 ssr-plus 自己要选择对应的 core )
  24. │ │         Mail  --->                                             │ │
  25. │ │         Multimedia  --->                                       │ │
  26. │ │         Network  --->                                          │ │ (选择了 smartdns)
  27. │ │         Sound  --->                                            │ │
  28. │ │         Utilities  --->                                        │ │
  29. │ │         Xorg  --->                                             │ │
复制代码

最后使用方向键导航到下方的 回车保存, 不要修改 .config 命名的文件名, 使用 make 编译时会默认使用.

下载 dl 库并编译
首次编译需要建议使用单线程编译:
  1. make download -j8
复制代码

编译后生成的路径是 bin/targets 目录, 一般使用 xxx-sysupdate.bin 进行升级.

二次更新流上最新代码编译
  1. cd lede
复制代码

重新配置编译
  1. rm -rf ./tmp && rm -rf .config
复制代码

FAQ (问题)
  • 巧用 tar 压缩命令解决磁盘空间不够的问题
    我使用的云服务器有 50G 的空间, 之前有在编译其它大型程序(差不多 30 G), 所以剩余可用的空间只有几个 G. 但之前的编译又不能删除, 那只能压缩一部分空间出来了.
    常规压缩的话磁盘空间也不够, 因为原始文件并没有删除. 后面查了一下资料, 可以使用 tar 命令的 --remove-source-files 进行压缩, 一边压缩一边删除, 执行:
    1. tar -czf xxxx.tar.gz --remove-files xxxx
    复制代码
    通过压缩, 最终端释放了 15G 的空间出来.

  • 编译时出现 ld returned 解决.
    第一次编译时, 由于磁盘空间不够编译失败, 后面释放空间后,编译一直报这个错误.
    collect2: error: ld returned 1 exit status
    /home/ubuntu/lede/build_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/gcc-8.4.0/gcc/c/Make-lang.in:85: recipe for target cc1'' failed'

    通过删除 build_dir, staging_dir, tmp 目录重新编译解决.

  • 关于 easymesh 使用崩溃的问题?
    编译前有关注过 easymesh 问题, 在 github 的 issue 中有看到 batman 导致的崩溃问题, 相关问题讨论地址: https://github.com/coolsnowwolf/lede/issues/8417
    目前我使用最新 master ( 20220919) 源码编译, 第一次编译的简洁版本开启简单mesh 使用并没有问题, 后面陆续增加插件编译, 确实会出现开启就卡死的情况.
    经过编译插件信息对比发现应该是 adbyby-plus 插件与 ssr-plus 插件所依赖的 adbyby 冲突导致的, 把 adbyby-plus 插件替换为 adblock 即解决.

  • ssr-plus 使用 xray-core 无法连接网络.
    当增加 ssr-plus feeds后, 配置时需要选择 ssr-plus 的核心为 xray-core, 但在配置界面中无法看到 xray plus, 最终通过修改 .config 文件, 把 CONFIG_PACKAGE_xray-plugin=y 启用.



我的恩山、我的无线 The best wifi forum is right here.
好帖,帮顶
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

来自手机 | 显示全部楼层
2004比较好,2204其实也不错,1804不推荐
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛上一条 /1 下一条

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-28 15:58

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表