openwrt基础编译

openwrt基础编译

部署一个基础的Debian系统
配置如下图:
image.png

共享dl目录

1
2
mkdir ../dl
ln -s ../dl dl

如果需要重新配置:

1
2
3
rm -rf .config
make menuconfig
make V=s -j$(nproc)

编译完成后输出路径:bin/targets

以上为参考内容,下面实操

安装环境(来自lede)

1
2
3
4
5
6
7
8
9
    sudo apt update -y
    sudo apt full-upgrade -y
    sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
    bzip2 ccache clang cmake cpio curl device-tree-compiler flex gawk gcc-multilib g++-multilib gettext \
    genisoimage git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libfuse-dev libglib2.0-dev \
    libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libpython3-dev \
    libreadline-dev libssl-dev libtool llvm lrzsz msmtp ninja-build p7zip p7zip-full patch pkgconf \
    python3 python3-pyelftools python3-setuptools qemu-utils rsync scons squashfs-tools subversion \
    swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev

额外需要的内容

1
sudo apt install python3-venv

盘不够大,挂个盘先

1
2
3
4
5
6
sudo -i
fdisk /dev/sda1
mkfs.xfs /dev/sda1
mount /dev/sda1 openwrt/
chown -R ksqeib:ksqeib openwrt
exit

下载源码

1
2
3
cd /mnt/openwrt/
git clone [email protected]:immortalwrt/immortalwrt.git
cd immortalwrt

此时建议备份一次,或者使用复制后的,而不是直接在拉下来的进行修改,可以节约后续为其他路由器编译时拉取源码的时间

1
cp -R immortalwrt immortalwrt_bak

可以使用openwrt编译添加小猫包(其他文章)而不是用下段代码
常规:

1
2
3
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig

添加小猫包的:

1
2
3
4
5
6
sed -i '$a src-git kenzo https://github.com/kenzok8/openwrt-packages' feeds.conf.default
sed -i '$a src-git small https://github.com/kenzok8/small' feeds.conf.default
git pull
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig

根据需求参考编译自定义合集进行修改

代理配置

使用国内镜像加速更新 crate 拉取

将如下配置写入 $HOME/.cargo/config 文件

 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
# 放到 `$HOME/.cargo/config` 文件中
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 替换成你偏好的镜像源
replace-with = 'sjtu'

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc 1号源
[source.rustcc]
registry = "git://crates.rustcc.com/crates.io-index"

# rustcc 2号源
[source.rustcc2]
registry = "git://crates.rustcc.cn/crates.io-index"
1
2
3
4
export GOPROXY="https://mirrors.aliyun.com/goproxy"
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
export CARGO_BUILD_JOBS=16

开始下载

1
 make download -j8

开始编译

1
make V=s -j16

为什么不是j1?
先j16编译,报错再j1来提速

编译完成去找我们的编译后文件
bin/targets

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计