创建用户
ssh [email protected]
sudo su root
useradd -m openwrt && chsh -s /bin/bash
echo openwrt:111111 | chpasswd
vim /etc/sudoers
su - openwrt && cd ~
安装依赖
sudo apt update && sudo apt dist-upgrade
sudo apt -y install build-essential asciidoc binutils bzip2 gawk gettext \
git libncurses5-dev libz-dev patch python3 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 wget curl swig rsync
克隆仓库
git clone https://www.github.com/openwrt/openwrt
git clone https://github.com/vernesong/OpenClash && mv OpenClash/luci-app-openclash openwrt/package
git clone https://github.com/rufengsuixing/luci-app-zerotier && mv luci-app-zerotier openwrt/package
cd openwrt
./scripts/feeds update -a && ./scripts/feeds install -a
./scripts/feeds install -a -p luci
./scripts/feeds update -a && ./scripts/feeds install -a
修改配置
# 修改默认 IP
sed -i 's/192.168.1.1/192.168.111.2/g' package/base-files/files/bin/config_generate
# 配置编译项
make menuconfig
Target System (x86) ---> 目标系统(x86)
Subtarget (x86_64) ---> 子目标(x86_64)
Target Profile (Generic) ---> 目标配置文件(通用)
Target Images ---> 保存目标镜像的格式
Global build settings ---> 全局构建设置
Advanced configuration options (for developers) ---> 高级配置选项(适用于开发人员)
Build the OpenWrt Image Builder ---> 构建 OpenWrt 图像生成器
Build the OpenWrt SDK ---> 构建 OpenWrt SDK
Package the OpenWrt-based Toolchain ---> 打包基于 OpenWrt 的工具链
Image configuration ---> 图像配置
Base system ---> 基本系统
Administration ---> 管理
Boot Loaders ---> 引导加载程序
Development ---> 开发
Extra packages ---> 额外包
Firmware ---> 固件
Fonts ---> 字体
Kernel modules ---> 内核模块
Languages ---> 语言
Libraries ---> 动态库
LuCI ---> LuCI
Mail ---> 邮件
Multimedia ---> 多媒体
Network ---> 网络
Sound ---> 声音
Utilities ---> 实用程序
Xorg ---> Xorg
## 选择系统 (以 x86_64 为例)
Target System -> x86
Subtarget -> x86_64
## 选择固件的文件系统
## https://openwrt.org/docs/techref/filesystems
Target Images -> squashfs
## 选择构建 x86_64 的 GRUB 固件
Target Images -> Build GRUB images (Linux x86 or x86_64 host only)
## 选择更小的压缩格式固件,方便复制
Target Images -> GZip images
## 修改软件包可用空间,默认安装会占用 100M 左右,建议修改扩大,为后续安装其他软件打基础
Target Images -> Root filesystem partition size
## 添加web界面 (y 键选择、 n 键排除)
LuCI > Collections -> Luci
## 添加兼容性依赖
LuCI > Modules -> luci-compat
## 添加中文
LuCI > Modules -> Translations -> Chinese Simplified
## 添加 openclash、zerotier
LuCI > Applications -> luci-app-openclash
LuCI > Applications -> luci-app-zerotier
## 添加主题
LuCI -> Themes
## 添加wget
Nerwork -> File Transfer -> wget-ssl
## 添加 kmod-tun,TUN 模式必须
Kernel modules -> Network Support -> kmod-tun
## 排除 dnsmasq,由于默认会安装 dnsmasq-full,这里需要排除 dnsmasq,否则会冲突报错。
Base system -> dnsmasq
开始编译
export http_proxy=192.168.111.102:6152
export https_proxy=192.168.111.102:6152
export all_proxy=192.168.111.102:6152
# 下载编译所需的软件包
make download -j8 V=s
# 编译固件
make -j8 V=s
# 查看固件
ls -lrth bin/targets/x86/64/*.gz
安装系统
scp bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz [email protected]:/tmp
ssh [email protected]
cd /tmp && gzip -d openwrt-x86-64-generic-squashfs-combined.img.gz
dd if=openwrt-x86-64-generic-squashfs-combined.img of=/dev/sda
reboot
配置系统
echo -n > ~/.ssh/known_hosts
ssh [email protected] # 默认密码:password
passwd root
# 浏览器访问 http://192.168.111.2 登录并配置接口、网关、DNS、防火墙、代理、内网穿透
更新编译
su - openwrt && cd ~
sudo apt update && sudo apt dist-upgrade
cd ~/openwrt && git pull
./scripts/feeds update -a && ./scripts/feeds install -a
make clean # 清理旧文件
make dirclean # 如需更换架构,深度清理
rm -rf ./tmp && rm -rf .config && make menuconfig # 如果需要对组件重新调整,清除配置
make download -j8 V=s # 下载编译所需的软件包
make -j8 V=s # 编译固件
原创
编译 OpenWrt 固件
本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
赞赏支持
如果觉得文章对你有帮助,可以请作者喝杯咖啡 ☕
评论交流
欢迎留下你的想法