原创文章,转载请注明出处
https://qiedd.com/

序言

openwrt是一个强大的、开源的路由器固件,基于Linux开发,并支持多种平台,今天我们来讲讲如何编译固件

openwrt官网:https://openwrt.org/

安装依赖

Debian/Ubuntu

sudo apt-get update

sudo apt-get install subversion g++ zlib1g-dev build-essential git \
python python3 python3-distutils libncurses5-dev gawk gettext unzip \
file libssl-dev wget libelf-dev ecj fastjar java-propose-classpath

CentOS

# 某些包需要用到epel-release
sudo yum install epel-release -y

sudo yum install binutils bzip2 gcc gcc-c++ gawk gettext flex \
ncurses-devel zlib-devel zlib-static make patch unzip openssl-devel \
perl-ExtUtils-MakeMaker glibc glibc-devel glibc-static ncurses-libs \
sed sdcc intltool sharutils bison wget git-core xz

ArchLinux

pacman -S --needed bash bc bin86 binutils bzip2 cdrkit core/which \
diffutils fastjar findutils flex gawk gcc gettext git intltool \
libusb libxslt make ncurses openssl patch perl-extutils-makemaker \
pkgconf python3 rsync sharutils time unzip util-linux wget zlib 

sudo pacman -S python-sphinx emacs

或者使用Aur源

yay -S openwrt-devel

sudo pacman -S python-sphinx emacs

更多操作系统可查阅wiki

https://openwrt.org/docs/guide-developer/build-system/install-buildsystem

下载源码

把Openwrt的源码git到本地

git clone https://github.com/openwrt/openwrt

更新源

./scripts/feeds update -a

将下载好的包安装

./scripts/feeds install -a

进入编辑界面

make menuconfig

选择你需要编译的内容

空格建为选择,上下左右建可移动选择条,返回上一页请使用<Exit>

参数解释(部分)

Target System:你的路由器的Soc架构

Subtarget:你的路由器Soc的型号

Target Profile:你的路由器的型号

Build the OpenWrt SDK:是否选择编译SDK,按需选择
SDK可用于交叉编译

Libraries:Linux的库

LuCI:路由器的网页界面

Utilities:Linux下的工具

编译示例

需求

使用Mentohust破解校园网,并且还要很过分的进行多拨
首先选择我们的路由器信息
联发科的MIPS架构,MT7621,网件的R6800

我们需要交叉编译 Mentohust,因此需要编译SDK

Mentohust 需要依赖 Libpcap,因此要在 Libraries 中选择 Libpcap

我们还需要Luci来管理路由器

进入 LuCI->Collections->勾选luci

<Exit> 返回上一页,进入 Modules->Translations
翻到最下面,勾选 Chinese Simplified (zh_Hans)

因为还想压榨校园网的所有带宽,我们还要进行多拨
因此需要 luci-app-wan3kmod-macvlan

LuCI –> Applications –> luci-app-mwan3
Kernel modules –> Network Devices –> kmod-macvlan

最后通过 <Save> 保存配置即可(回车保存即可)
然后一路 <Exit>退出来

编译

新手建议使用单线程编译

make -j1 V=s

但是单线程编译很慢,那么就自信点,直接使用多线程编译吧

make -j你的CPU线程数 V=s
#可使用lscpu查看你的CPU线程数

编译完成和可在 bin/targets/ramips/mt7621/ 中找到你的固件

此为示例固件名称:
openwrt-ramips-mt7621-netgear_r6800-squashfs-sysupgrade.bin

将其刷入进你的路由器即可

二次编译

由于Openwrt的源码更新频繁,你又想使用最新的源码,那么就需要拉取最新的源码

#进入openwrt的文件夹
cd openwrt

#拉取最新源码
git pull

#更新应用和安装
./scripts/feeds update -a
./scripts/feeds install -a

#重新生成菜单
make deconfig

#编译
make -j你的CPU线程数 V=s

其他

若一直编译失败,建议挂全局代理,然后

make clean

若需重新配置

#删除配置文件
rm .config

#重新生成
make menuconfig


0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据