编译并配置带 OpenClash 的 OpenWrt 固件。
OpenWrt 是开源的、基于 Linux 的软路由系统,而 OpenClash 一个运行在 OpenWrt 上的 Clash 客户端,兼容Shadowsocks、Vmess、Trojan、Snell 等协议,根据灵活的规则配置策略代理,把 OpenClash 当网关做透明代理,该网段下的所有的设备无需设置,即可自动实现科学上网。
网上有很多修改过的 OpenWrt 固件,但集成 OpenClash 的固件比较少,本文将记录一下编译纯净的 OpenWrt 固件,并集成 OpenClash。
前言
- 系统我使用的 Debian 10
- 由于会下载大量国外数据,建议国内用户全程在科学上网环境下编译。
- 编译时会产生大量临时数据,建议至少预留20G的空闲空间和4G以上内存
开始
使用root用户安装所需软件依赖
1 2 3 4 5 6 7
| apt update
apt 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 curl
|
以下操作全部以非root用户执行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| cd ~
git clone https://github.com/openwrt/openwrt
wget https://github.com/vernesong/OpenClash/archive/master.zip
unzip master.zip
cp -r OpenClash-master/luci-app-openclash openwrt/package
cd openwrt ./scripts/feeds update -a ./scripts/feeds install -a
|
输入make menuconfig
进入交互式配置界面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Target System (x86) ---> 目标系统(x86) Subtarget (x86_64) ---> 子目标(x86_64) Target Profile (Generic) --->目标配置文件(通用) Target Images ---> 保存目标镜像的格式 Global build settings ---> 全局构建设置 Advanced configuration options (for developers) ---- 高级配置选项(适用于开发人员) Build the OpenWrt Image Builder 构建OpenWrt图像生成器 Build the OpenWrt SDK 构建OpenWrt SDK Package the OpenWrt-based Toolchain 打包基于OpenWrt的工具链 Image configuration --->图像配置 Base system ---> 基本系统 Administration ---> 管理 Boot Loaders ---> 引导加载程序 Development ---> 开发 Extra packages ---> 额外包 Firmware --->固件 Fonts --->字体 Kernel modules ---> 内核模块 Languages --->语言 Libraries ---> 图书馆 LuCI ---> LuCI Mail ---> 邮件 Multimedia --->多媒体 Network --->网络 Sound ---> 声音 Utilities --->实用程序 Xorg --->Xorg
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Target System -> x86 Subtarget -> x86_64
Target Images -> squashfs
Target Images -> Build GRUB images (Linux x86 or x86_64 host only)
Target Images -> GZip images
Target Images -> Root filesystem partition size
LuCI > Collections -> Luci
LuCI > Modules -> luci-compat
LuCI > Modules -> Translations -> Chinese Simplified
LuCI > Applications -> luci-app-openclash
LuCI -> Themes
Nerwork -> File Transfer -> wget-ssl
Kernel modules -> Network Support -> kmod-tun
Base system -> dnsmasq
|
开始编译
1 2 3 4 5 6 7
|
make -j8 download V=s
make -j4 V=s
|
编译时间很长,一般要30分钟以上
编译完成后的固件xx-squashfs-combined.img.gz
在openwrt/bin/targets/x86/64/
目录下
二次更新编译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| cd ~
rm -rf master.zip && rm -rf OpenClash-master && rm -rf openwrt/package/luci-app-openclash
wget https://github.com/vernesong/OpenClash/archive/master.zip
unzip master.zip
cp -r OpenClash-master/luci-app-openclash openwrt/package
cd openwrt
git pull
./scripts/feeds update -a ./scripts/feeds install -a
make menuconfig
make -j8 download V=s
make -j4 V=s
|
ProxmoxVE安装OpenWrt
新建虚拟机,记住VM ID
,这里以300为例;操作系统选择不使用任何介质;系统默认;硬盘随便分配1G,稍后需要手动删除的;CPU、内存、网络自行配置。
将编译好的 OpenWrt 固件放入 PVE 根目录。
1 2 3 4 5 6 7
| cd ~
gunzip xx-squashfs-combined.img.gz
qm importdisk 300 ./openwrt.img local-lvm
|
转换完,在虚拟机硬件界面应该会多出一个未使用磁盘。将创建虚拟机时分配的磁盘分离删除,选择转换的 OpenWrt 磁盘点击编辑添加。