Leadaxe 说明 sing-box-lx 不计划官方提供 UPX 压缩版的原因,并给出减小体积的替代方案
回复「为 OpenWrt 提供压缩版」的请求:不计划官方提供 UPX 打包的二进制。原因:UPX 二进制每次启动会把整个二进制解压到匿名内存(当前 linux-arm64 约 75 MB),比普通二进制的按需分页占用更多内存,最需要小体积的 128 MB mipsle 路由器上反而可能导致 sing-box 或其他服务被 OOM 杀死;且 UPX 与静态 Go 二进制在部分架构(尤其 MIPS)有已知问题、弱 CPU 上启动更慢,每次 UPX 或 Go 新版本都需逐架构重测。MT7981/MT7986(filogic)板卡内存充足,可用下列方案。方案一(源码构建更小二进制):体积主要来自可选特性,linux-arm64(stripped、static)实测 Release 1.14.2-lx.11(完整 tag 集,含 NaïveProxy/cronet)74.7 MB,去掉 naive 约 64 MB,再去掉 tailscale 约 50 MB;为纯 Go 静态构建(CGO_ENABLED=0),无需交叉编译器。需 checkout 相应 release tag、初始化 forked 的 gvisor/sing-tun/utls/wireguard-go 子模块(必需)、按 go.version 设置 GOTOOLCHAIN,再以默认 tag 集去掉 with_naive_outbound、with_purego、with_tailscale 构建;badlinkname 与 tfogo_checklinkname0 始终必需。方案二(无需重新构建):extroot 把 /overlay 移到 U 盘或空闲分区;只保留约 30 MB 的 .tar.gz 并在启动时解压到 tmpfs(512 MB 以上板卡可用);启动时下载到 /tmp。
作者原文@LeadaxeThanks for the request. I assume "compressed" means UPX-packed binaries. We're not planning to ship those officially, for these reasons:
- A UPX binary costs more RAM, not less. On every start the whole binary is unpacked into anonymous memory, about 75 MB for the current
linux-arm64. A normal binary is paged in on demand, and the kernel can drop and reload those pages under memory pressure. The routers that most need a smaller file on flash are the smallmipsleones with 128 MB RAM, and there a UPX build can lead to OOM kills of sing-box or other services. So it would hurt exactly the devices it's meant to help.- UPX with static Go binaries is fragile. There are known problems on some architectures, MIPS in particular, plus slower startup on weak CPUs. Every new UPX or Go release would need re-testing on each arch.
A MT7981/MT7986 (filogic) board has plenty of RAM, so some of the options below will work fine for you.
Option 1: build a smaller binary from source
Most of the size comes from optional features. Measured on
linux-arm64(stripped, static):| Build | Size |
|---|---|
| Release1.14.2-lx.11(full tag set, with NaïveProxy/cronet) | 74.7 MB |
| Withoutnaive(no cronet) | ~64 MB |
| Withoutnaiveand withouttailscale| ~50 MB |This is a pure-Go static build (
CGO_ENABLED=0), so you don't need a cross-compiler. It runs on OpenWrt/musl as is.git clone https://github.com/Leadaxe/sing-box-lx.git cd sing-box-lx git checkout v1.14.2-lx.11 # or the latest release tag # the forked wireguard-go / sing-tun / utls / gvisor are submodules — required git submodule update --init --depth=1 \ submodules/gvisor submodules/sing-tun submodules/utls submodules/wireguard-go # Go version is pinned in ./go.version (currently 1.26.x) export GOTOOLCHAIN="$(cat go.version)" # Default tag set minus with_naive_outbound, with_purego and with_tailscale TAGS=with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_clash_api,badlinkname,tfogo_checklinkname0,with_xhttp,with_awg,with_lx_command,with_lxd,with_openvpn,with_openconnect,with_lx_chain GOOS=linux GOARCH=arm64 make -f Makefile.lx lx-build LX_TAGS="$TAGS" # for mipsle routers: GOOS=linux GOARCH=mipsle GOMIPS=softfloat make -f Makefile.lx lx-build LX_TAGS="$TAGS"
- Keep
with_tailscalein the list if you use thetailscaleendpoint.badlinknameandtfogo_checklinkname0are always required.- If you don't use them, you can also drop
with_openvpn,with_openconnect,with_clash_api(external dashboards) orwith_lxd(the lxd daemon) to save a few more MB.- Run
make -f Makefile.lx lx-print-tagsto see the full default set.Option 2: workarounds without rebuilding
- extroot: move
/overlayto a USB drive or a spare partition. This is the standard OpenWrt answer to a small flash, and after that the full release binary fits.- Keep only the
.tar.gzon flash and unpack to tmpfs at boot. The archive is about 30 MB. Unpack it to/tmpfrom the init script (tar xzf … -C /tmp) and start/tmp/.../sing-box. The binary then sits in RAM (tmpfs), which is fine on a board with 512 MB or more. On a 128 MB router this has the same RAM problem as UPX.- Download at boot to
/tmp: same idea with nothing stored on flash. It needs working WAN/DNS before the proxy starts, so it's less robust.Generated by Claude Code