WSL下编译OpenWrt/LEDE笔记

WSL的安装参见Windows10 玩SmartDNS告别污染
最好别装在默认的C盘,编译文件量巨大(占用空间近6G)

环境准备

参考: 文献1, 文献2
替换国内源 Ubuntu国内源

# 命令
sudo nano /etc/apt/sources.list
# 文件开头处插入
deb http://mirrors.163.com/debian/ stretch main non-free contrib
deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib

更新环境软件包 命令:sudo sh -c "apt update && apt upgrade -y"
安装依赖包:

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 rsync

取消WSL PATH 与windows PATH关联

#在Debian中修改/etc/wsl.conf
sudo nano /etc/wsl.conf
#加入内容
[interop]
appendWindowsPath=false
[automount]
enable=false
#管理员身份cmd运行以下命令重启wsl
net stop LxssManager 
net start LxssManager
#查验环境变量看效果
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
#上面看不到Windows环境路径就对了

将Debian目录设置为大小写敏感路径 参考

fsutil.exe file setCaseSensitiveInfo enable

加速连接

前面的参考文都采用的系统代理的方式加速,我这里代理效果不佳,常常TimeOut,所以采用了镜像连接的方法

# 原GitHub
https://github.com/coolsnowwolf/lede.git
# 镜像连接
https://gitclone.com/github.com/coolsnowwolf/lede.git  # 杭州
https://hub.fastgit.org/coolsnowwolf/lede.git  # 香港
https://github.com.cnpmjs.org/coolsnowwolf/lede.git  # 新加坡

这里使用新加坡镜像为例:参考1, 参考2

# 切换至用户目录 (必须)
cd /home/UserName
# 克隆镜像
git clone https://github.com.cnpmjs.org/coolsnowwolf/lede.git
cd lede
# 添加 feed 源
sed -i '$a src-git lienol https://github.com/Lienol/openwrt-package' feeds.conf.default
sed -i '$a src-git kenzok8 https://github.com/kenzok8/openwrt-packages' feeds.conf.default
sed -i '$a src-git small https://github.com/kenzok8/small' feeds.conf.default
# 替换镜像连接
sed -i 's/github.com/&.cnpmjs.org/g' ./feeds.conf.default
sed -i 's/github.com\//github.com.cnpmjs.org\//g' `grep -l -e github.com/.*/.*\.git ./package/lean/*/Makefile`
./scripts/feeds clean
./scripts/feeds update -a  #最好多执行几次, 放置下载失败
./scripts/feeds install -a

编译

以编译极路由B70硬改SPI版为例:

# 修改默认网址
sed -i 's/192.168.1.1/192.168.77.1/g' ./package/base-files/files/bin/config_generate
# 下载dts配置文件
wget -P ./target/linux/ramips/dts/ https://raw.sevencdn.com/lon91ong/OpenWRT_B70_SPI_16M/master/mt7621_hiwifi_hc5962-spi.dts
sed -i 's/hc5962/&|\\\n\thiwifi,hc5962-spi/g' ./target/linux/ramips/mt7621/base-files/etc/board.d/02_network
# 添加设备信息
cat >> ./target/linux/ramips/image/mt7621.mk </<0x50000 0x1fb0000>/g' ./target/linux/ramips/dts/mt7621_hiwifi_hc5962-spi.dts
sed -i 's/16064/32128/g' ./target/linux/ramips/image/mt7621.mk
# 修改默认主题
sed -i 's/luci-theme-bootstrap/luci-theme-argon/g' ./feeds/luci/collections/luci/Makefile
rm -f ./.config*
touch ./.config
# ===========固件定制部分=============
# 编译极路由B70固件:
cat >> .config <

配置结束,编译预备:

# 最后下载dl库, 多执行几次, 实在下不动的用工具下之后复制过来
make -j8 download V=s
# 手动复制过来的需要添加权限644
sudo chmod 644 ./dl/*
# 开始编译, (-j 后面是线程数。第一次编译推荐用单线程) 
make -j1 V=s

第一次编译耗时大约1小时左右, 具体看电脑配置。
以后编译可以使用多线程,速度更快:参考

make dirclean //清除上一次编译产生的垃圾
make download -j8 V=s
make -j6 V=s

编译好的固件位置:

编译工作目录(/home/UserName/lede)./bin/targets/(CPU架构)..openwrt-*-squashfs-sysupgrade.bin

END

你可能感兴趣的:(WSL下编译OpenWrt/LEDE笔记)