源码:https://github.com/openwrt/openwrt
固件:https://downloads.openwrt.org
以 root 用户或者有 root 权限的用户执行以下命令
直接抄大佬的环境 Requirements
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 ecj fastjar flex gawk gettext gcc-multilib \
g++-multilib git gnutls-dev gperf haveged help2man intltool lib32gcc-s1 libc6-dev-i386 libelf-dev \
libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses-dev libpython3-dev \
libreadline-dev libssl-dev libtool libyaml-dev libz-dev lld llvm lrzsz mkisofs msmtp nano \
ninja-build p7zip p7zip-full patch pkgconf python3 python3-pip python3-ply python3-docutils \
python3-pyelftools qemu-utils re2c rsync scons squashfs-tools subversion swig texinfo uglifyjs \
upx-ucl unzip vim wget xmlto xxd zlib1g-dev zstd
或者
sudo bash -c 'bash <(curl -s https://build-scripts.immortalwrt.org/init_build_environment.sh)'
以下命令以普通用户执行,不要用 root
git clone -b v24.10.0 --single-branch --depth=1 https://github.com/openwrt/openwrt.git
相关信息
-b 指定分支/标签、 --single-branch 仅下载单个分支/标签、 --depth=1 只下载最新的一次提交
# 修改时区
sed -i '/set system.@system\[\-1\].timezone=.*/c\ set system.@system[-1].timezone='\''CST-8'\''' package/base-files/files/bin/config_generate
# 设置时区名称
sed -i '/set system.@system\[\-1\].timezone=.*/a\ set system.@system[-1].zonename='\''Asia/Shanghai'\''' package/base-files/files/bin/config_generate
默认管理IP为 192.168.1.1 ,可以根据自己的需求进行修改
sed -i 's/192.168.1.1/10.0.0.2/g' package/base-files/files/bin/config_generate
执行以下命令打开菜单配置
按照如下配置进行选择,其他未说明的不要动
Target System -> x86Subtarget -> x86_64Target Images- < >
tar.gz - < >
ext4 - < >
Build GRUB images - (1)
Seconds to wait before booting the default entry - (256)
Root filesystem partition size
Base system- < >
dnsmasq # 二选一 - <*>
dnsmasq-full # 二选一
Libraries- < >
libustream-mbedtls - <*>
libustream-openssl #与 helloworld 保持一致 - < >
libustream-wolfssl
LuCICollectionsModulesApplications
Network
这里会先把编译时要下载的文件下载下来(只是一部分,后面编译阶段还会下载,仍需保持网络畅通)
根据CPU核心数开启指定线程数
相关信息
如果编译过程中报错了,可以使用单线程模式 make V=s -j1 ,确认出错的地方,然后排查(注:有时候单线程就不报错了),使用 -j 参数可以指定编译时使用的线程数
# 进入目录
cd openwrt
# 拉取更新
git pull
# 更新系统组件
./scripts/feeds update -a && ./scripts/feeds install -a
# 生成配置文件
make defconfig
# 下载源码文件
make download -j8
# 使用 WSL/WSL2 进行编译
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 执行编译
make V=s -j$(nproc)
# 清除缓存和配置文件
rm -rf ./tmp && rm -rf .config
# 打开配置菜单
make menuconfig
# 下载源码文件
make download -j8
# 使用 WSL/WSL2 进行编译
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 执行编译
make V=s -j$(nproc)
make defconfig
./scripts/diffconfig.sh > seed.config
使用 OpenWrt 23.05.5 官网源码编译固件
【openwrt】openwrt内核编译libustream-openssl出错 解决-谷动谷力