OpenWRT 编译前后相关命令整理
一、查看系统环境
# 系统环境
lsb_release -a # Ubuntu/Debian
uname -a # 内核版本
二、安装编译依赖
参考 https://github.com/coolsnowwolf/lede#编译命令
三、下载源代码,更新 feeds 并选择配置
git clone https://github.com/coolsnowwolf/lede
cd lede
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
四、预下载 dl 库,编译固件
make download -j8 V=s
# 检查文件完整性
find dl -size -1024c -exec ls -l {} \;
# 第一次编译推荐用单线程
# make V=s -j1
# 多线程编译并保存日志
make -j$(nproc) V=s | tee ../compile.log
# 成功生成镜像路径示例
bin/targets/x86/64/openwrt-*-x86-64-generic-ext4-combined.vmdk
五、日志检查依赖与错误
cat ../compile.log | grep ERROR:
cat ../compile.log | grep failed
# 依赖问题
grep "missing" compile.log # 检查缺失依赖
grep "Error 127" compile.log # 命令未找到
# 工具链错误
grep -A 10 "toolchain" compile.log # 检查交叉编译器错误
# 软件包下载失败
cat compile.log | grep "Download failed" # 查看下载失败包
ls -lh dl/ # 检查dl目录内容
# 内核/驱动错误
grep -i "warning" compile.log | grep -i "driver" # 驱动相关警告
grep "Kernel panic" compile.log # 内核崩溃
六、二次编译
cd lede
git pull
./scripts/feeds update -a
./scripts/feeds install -a
make defconfig
make download -j8
make V=s -j$(nproc)
七、重新配置
rm -rf .config
make menuconfig
make V=s -j$(nproc)
八、自定义内容的.config导出与还原
# 导出差异部分到 diffconfig 文件
./scripts/diffconfig.sh > diff.config
# 还原配置
# 注意:还原时文件名必须为 .config
make defconfig
九、清理编译产物
# 清除旧的编译产物
make clean
# 清除旧的编译产物、交叉编译工具及工具链等目录(可选)
make dirclean
# 清除 OpenWrt 源码以外的文件(可选)
make distclean
# 清除编译缓存
rm -rf tmp
# 删除配置文件(可选)
rm -f .config
> Cleaned components > v make argument v | Compiled binaries: firmware, kernel, packages | Toolchain (target-specific) | Build tools, tmp/ | Compiled config tools | .config | feeds, .ccache, downloaded source files |
---|---|---|---|---|---|---|
clean | x | |||||
targetclean | x | x | ||||
dirclean | x | x | x | x | ||
config-clean | x | |||||
distclean | x | x | x | x | x | x |
十、插件的查找与重新编译
# 查找插件目录
find feeds/ -name "luci-app-upnp"
# 自添插件查找
# find -name "luci-app-upnp"
# 修改某插件后强制重编译
make package/feeds/luci/luci-app-*/{clean,compile} V=s
# 自行添加插件强制重编译
# make package/helloworld/luci-app-upnp/{clean,compile} V=s
# 查看文件修改时间是否编译成功
find bin/ -name "luci-app-upnp*.ipk" -exec ls -l {} \;
十一、编译后的IPK速部署方法(无需完整编译)
找到新编译的 IPK 文件
IPK_PATH=$(find bin/ -name "luci-app-upnp*.ipk")
echo $IPK_PATH
将 IPK 文件复制到路由器
scp $IPK_PATH root@路由器IP:/tmp/
在路由器上安装更新
ssh root@路由器IP
opkg install --force-reinstall /tmp/luci-app-upnp*.ipk
/etc/init.d/rpcd restart
十二、部分模块在 编译环境中使用代理
在编译命令前添加环境变量:
更换 Go 模块代理
export GOPROXY=https://goproxy.cn,direct
Rust/Cargo 代理设置方法
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
export CARGO_HTTP_MULTIPLEXING=false # 解决某些网络环境下的问题
或者使用其他国内镜像:
# 中科大镜像
export RUSTUP_DIST_SERVER="https://mirrors.ustc.edu.cn/rust-static"
export RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup"
# 清华大学镜像
export RUSTUP_DIST_SERVER="https://mirrors.tuna.tsinghua.edu.cn/rustup"
十三、PVE使用qcow2镜像文件
转换为 LVM/thin 等高性能格式(推荐)
使用 qm importdisk
命令:
# 语法:qm importdisk <VMID> <镜像路径> <存储名> --format <目标格式>
qm importdisk 100 /var/lib/vz/template/iso/your-image.qcow2 local-lvm --format qcow2
100
:新虚拟机的 ID(需提前创建空 VM 或指定新 ID)。local-lvm
:存储名称(替换为你的存储)。--format qcow2
:保留 qcow2 格式(或改为raw
提升性能)。