从零开始的OpenWRT编译

最近在捣鼓一台旧的路由器,由于一直靠在论坛用别人自己编译的固件,且各个固件都有所好处,所以决定自己编译一个最合适自己的固件

首先是准备工作

sudo apt-get update  
sudo apt-get install git-core build-essential libssl-dev libncurses5-dev unzip  
sudo apt-get install subversion mercurial  
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev 

sudo apt-get install gawk asciidoc libz-dev libssl-dev time

Debian的vps可能需要新建一下用户

引用一下zouyongjin的教程

文中的humou均改成自己想要的用户名

注意事项:

1. 请使用一个非root用户来完成这些工作!
2. 这里的所有命令都在OpenWrt编译系统的根目录下运行(例如~/openwrt/trunk/)
3. 编译系统的绝对路径中不能含有空格!
4. 如果你使用root用户下载了源码,请把你下载来的源码的所有者更改为一个非root用户。(sudo chown -R user:user /openwrt/)

1.接下来是获取Openwrt源码

git clone https://git.openwrt.org/openwrt/openwrt.git

等待代码下载。结束后,目录下会出现openwrt文件夹

2.进入openwrt目录,执行

./scripts/feeds update -a

./scripts/feeds install -a

3.配置编译选项:

make menuconfig 

用方向键、空格(选择,出现M代表编译但不编译到固件,*号(按y也有)表示编译进固件)、按两下esc返回等操作来配置选项,本人的路由器是newifi mini,配置如下(大部分为针对我需求的选项):


Target System --> MediaTek Ralink MIPS

Subtarget --> MT7620 based boards

Target Profile --> Lenovo Y1

Package the OpenWrt-based Toolchain

Base system --> block-mount

                                libstdcpp

Kernel moudules --> Filesytems --> kmod-fs-ext4

                                                       kmod-fs-ntfs

                                                       kmod-fs-vfat(可要可不要)

                                 Native Language Support ---> kmod-nls-utf8

                                 USB Support ---> kmod-usb-ohci

                                                             kmod-usb-storage

                                                             kmod-usb-storage-extras

                                                             kmod-usb-uhci

                                                             kmod-usb2

Libraries --> SSL --> libopenssl

                 libffmpeg-mini

                 libxml2

LuCI --> Collections --> luci

             Modules --> Translations -->Chinese

             Applications --> luci-app-aria2

                                   luci-app-hd-idle

                                   luci-app-minidlna

                                   luci-app-ntpc

                                   luci-app-samba

                                   luci-app-transmission

                                   luci-app-uhttpd

                                   luci-app-upnp

              Theme --> luci-theme-material

Network --> BitTorrent --> transmission-daemon-openssl

                                     transmission-remote-openssl

                                     transmission-web

                  Downloas Manager --> ariang

                                                 webui-aria2

                                                 yaaw

                   File Transfer --> curl

                                          vsftpd

                   Time Synchronization --> ntpclient

Utilities —> Filesystem —> <*> badblocks

                                            ntfs-3g

Utilities  ---> disc ---> <*> fdisk

Utilities  ---> <*> usbutils

最后save并按两次esc

4.编译

make V=s -j8
输出为
Signing package index...
make[2]: Leaving directory '/home/echo/openwrt'
export MAKEFLAGS= ;make -w -r checksum
make[2]: Entering directory '/home/echo/openwrt'
make[2]: Leaving directory '/home/echo/openwrt'
make[1]: Leaving directory '/home/echo/openwrt'

这时可在~/openwrt/bin/targets/ramips/mt7620中找到固件openwrt-ramips-mt7620-y1-squashfs-sysupgrade.bin


错误总结:

在编译过程中会碰到各种奇怪的错误,不过通常都是因为没有安装好编译所需的工具,例如gawk等等,希望这篇文章能帮各位解决一小部分问题

感谢GoldMoon所写的教程,帮我解决初期的大部分问题,他的文章地址点击打开链接

猜你喜欢

转载自blog.csdn.net/a1246526429/article/details/80344889