windows10 Ubuntu子系统编译openwrt

前言

其他openwrt的编译步骤网上几乎都一样,网络问题比较头疼。去买了一个vps,结果内存太小了,cpp不够编译。只有一核也编不过去。后面使用window10自带的ubuntu子系统,编译。下面是编译步骤,和遇到的所有问题。最好是把网络问题解决了,不然会遇到一堆奇奇怪怪的问题。

编译步骤

大致有以下步骤:

  1. 下载源码
git clone xxxxxxxx(看你是用的哪一个分支)
  1. 下载一些包(这里要是不科学冲浪会很慢)
./scripts/feeds update -a
./scripts/feeds install -a
  1. 选择以下要编译什么内容
make menuconfig(CPU啥的选一下,就能用,其他的看情况)
  1. 如果使用root编译加上这一条
export FORCE_UNSAFE_CONFIGURE=1
  1. 然后就等编译
make V=99

网络问题

有很多dl目录下的文件下载太慢,或者根本下载不了

1.使用其他源,(有很多问题)
2.挂代理(我用的方法)

使用代理

我这边用的是*

  1. 打开软件
    windows10 Ubuntu子系统编译openwrt
    这里显示的是http 127.0.0.1:10809
  2. 打开ubuntu

nano ~/.bashrc

添加以下代码

# 我这里是服务器不支持https就和http设置成一样的
export http_proxy=http://127.0.0.1:10809
export https_proxy=http://127.0.0.1:10809
  1. 执行source ~/.bashrc
  2. 验证生效与否
root@DESKTOP-HAA4OOQ:~# curl http://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

如果不为空就可以了

openwrt root用户问题

openwrt是不推荐root编译的
会出现以下错误

configure: error: you should not run configure as root(set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)

按照他说的,输入 export FORCE_UNSAFE_CONFIGURE=1继续编译就行了

WSL环境变量问题

由于windows添加了一堆莫名其妙的环境变量上去,find出现警告。

sed -i "s/Installed-Time: .*/Installed-Time: 1610712340/" /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/usr/lib/opkg/status
rm -rf /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/boot /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/tmp/* /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/usr/lib/opkg/info/*.postinst* /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/usr/lib/opkg/lists/* /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/var/lock/*.lock
find /root/share/newifi/source/build_dir/target-mipsel_24kc_musl/root-ramips/ -mindepth 1 -execdir touch -hcd "@1610712340" "{}" +
find: The relative path 'Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2020.812.0_x64__79rhkp1fndgsc' is included in the PATH environment variable, which is insecure in combination with the -execdir action of find.  Please remove that entry from $PATH
make[2]: *** [package/Makefile:72: package/install] Error 1
make[2]: Leaving directory '/root/share/newifi/source'
make[1]: *** [package/Makefile:109: /root/share/newifi/source/staging_dir/target-mipsel_24kc_musl/stamp/.package_install] Error 2
make[1]: Leaving directory '/root/share/newifi/source'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/d/DevelopSoftWare/VMWare/bin/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/d/DevelopSoftWare/UltraEdit:/mnt/c/Program Files/Java/jdk-15.0.1/bin:/mnt/c/Program Files/Java/jdk-15.0.1/jre/bin:/snap/bin

解决办法如下:
1.先echo $PATH

root@DESKTOP-HAA4OOQ:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/d/DevelopSoftWare/VMWare/bin/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/d/DevelopSoftWare/UltraEdit:/mnt/c/Program Files/Java/jdk-15.0.1/bin:/mnt/c/Program Files/Java/jdk-15.0.1/jre/bin:/snap/bin

2.把其中一些/mnt/下的目录全删了,留下linux编译要用的

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

3.然后输入

export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'

4.验证以下echo $PATH 修改成功

上一篇:centos7.5安装apache


下一篇:发告警到钉钉上