本来ubuntu是编译openwrt 的最佳系统,那么wsl 的ubuntu 可以吗?当然也可以,同样的使用默认用户(非root),不一样的是wls下编译时会多出两个问题:

  • 环境变量问题,默认没有/usr/bin的Path,只有windows的path。make时会提示找不到find 全局命令行工具。添加export PATH=$PATH:/bin:/usr/bin 解决。
  • 大小写问题,默认windows 路径(/mnt/c/Users/winuser/Path),不区分大小写的,make时会提示小写敏感提示。把openwrt下载到ubuntu(/home/linuxuser/Path)目录下解决。

准备环境。

  • 安装全局依赖,参考官方链接

    sudo apt install build-essential clang flex bison g++ gawk \
    gcc-multilib g++-multilib gettext git libncurses-dev libssl-dev \
    python3-distutils python3-setuptools rsync swig unzip zlib1g-dev file wget
    
  • 下载源码,一般下载稳定版本的分支 23.05.2

    git clone https://github.com/openwrt/openwrt.git -b v23.05.2
    

    image-1745594802011

定制组件

默认的 feeds.conf.default

src-git packages https://git.openwrt.org/feed/packages.git^8e3a1824645f5e73ec44c897ac0755c53fb4a1f8
src-git luci https://git.openwrt.org/project/luci.git^7739e9f5b03b830f51d53c384be4baef95054cb3
src-git routing https://git.openwrt.org/feed/routing.git^83ef3784a9092cfd0a900cc28e2ed4e13671d667
src-git telephony https://git.openwrt.org/feed/telephony.git^9746ae8f964e18f04b64fbe1956366954ff223f8

举例说明,如果需要添加 passfwll,只需要在后面添加

src-git passfwll https://github.com/xiaorouji/openwrt-passfwll.git

下载并更新组件包

  • 下载检查并创建组件包索引到 package/feeds/
    ./scripts/feeds update -a && ./scripts/feeds install -a
    image-1745595386035

  • 排错,下图看出 dnsmasq 重复,passfwll三个依赖包缺失
    image-1745595778306

  • dnsmasq 重复是与dnsmasq-full冲突了,在make menuconfig的 交互界面勾掉即可,不然不要忘了在Luci->Applications 里勾上刚添加定制组件 luci-app-passfwll。

  • make menuconfig :选择本次编译的功能,从上面报错可知,添加功能很容易引起重复引用,交叉引用,部分引用等,要谨慎选择。

    Target System (x86)  --->   目标系统(x86)
    Subtarget (x86_64)  --->   子目标(x86_64)
    LuCI  --->    LuCI (web 界面)
    

    image-1745596147667

  • 三个依赖包,在网上找一下,然后手动添加

    cd ~/openwrt/package/feeds/passfwll
    git clone https://github.com/756yang/openwrt-tcping.git tcping
    mkdir -p  ~/openwrt/package/feeds/passfwll/chinadns-ng && cd  ~/openwrt/package/feeds/passfwll/chinadns-ng 
    wget https://raw.githubusercontent.com/illfool/openwrt-packages/main/chinadns-ng/Makefile
    mkdir -p  ~/openwrt/package/feeds/passfwll/dns2socks && cd  ~/openwrt/package/feeds/passfwll/dns2socks
    wget https://raw.githubusercontent.com/illfool/openwrt-packages/refs/heads/main/dns2socks/Makefile
    
    

正式编译

  • 修正组件依赖缺失和重复的错误后,开始编译
    make download -j8 V=s && make -j$(nproc) || make -j1 V=s
    image-1745596439773
    image-1745596496645

  • 在windows 中打开,在wsl 的终端 执行:
    /mnt/c/Windows/explorer.exe . #用windows的资源管理器 打开当前目录
    image-1745596615689

在PVE里安装

  • 导入空白VM
    image-1745597713790
    image-1745597798726
    image-1745597876970
  • 启动
    image-1745598084224
    image-1745599450116