A-A+

openwrt固件最简单编译过程以及编译界面汉化翻译。

本文于2016年05月30日最后更新 网络心得

鉴于大家安装出现的问题,张自然于20160226更新

推荐用国外32 位ubuntu kvm或者xen等全虚拟化vps

感谢@ryd994 为本文提出的众多改进建议,张自然也希望大家共同完善此教程,谢谢。

编译openwrt的准备工作

首先,我们安装一个ubuntu虚拟机。为了省事,张自然这里采用的是前几天参加活动的vultr云主机日本数据中心的1core,768M内存vps安装的是Ubuntu 14.10 i386系统。

这里需要注意的是一定要32位的系统,64位的系统也可以编译,但是有些莫名其妙的问题,具体原因张自然也不知道。20141215修改:(经@ryd994提醒,现在系统一般都有multiarch。multiarch就是允许安装多个架构软件包的一个东西。这是官方介绍:https://wiki.debian.org/Multiarch 。所以64位的应该也没多大问题的。)

进入Ubuntu 14.10 i386系统后,我们先更新下系统和安装下需要用到的软件包。

sudo apt-get update

sudo apt-get install subversion build-essential git-core libncurses5-dev zlib1g-dev gawk flex quilt libssl-dev xsltproc libxml-parser-perl mercurial bzr ecj cvs unzip

openwrt-vultr

openwrt-ubuntuupdate

下载安装openwrt源码

安装更新完以后我们开始下载安装openwrt。

由于git方式获取直接会自动创建openwrt目录,所以我们现在只需要cd切换到需要放源码的地方,下载完成后更新种子列表,更新种子在menuconfig中的显示列表就好了。

以下含义依次是创建openwrt目录,进入openwrt目录,获取trunk开发版SVN代码库,进入trunk目录,更新种子列表,最后更新种子在menuconfig中的显示列表。

(注释:Barrier Breaker和trunk为两个不同分支的openwrt源码,Barrier Breaker据说较为稳定,但是支持的路由器没有trunk多,trunk更多称之为测试版,但编译好后使用也没什么问题。编译的时候只需执行以上一条命令即可。执行完成后,会在openwrt下生成目录,使用Barrier Breaker源码生成backfire目录,trunk同理。至于openwrt Dreambox版本应该是中国的openwrt.org.cn衍生出的一个openwet版本。)。

 

因为张自然20160528重装系统下载时发现openwrt官方svn服务器无法连接

root@ubuntu-2gb-nyc3-01:~/openwrt# svn co svn://svn.openwrt.org/openwrt/trunk trunk
svn: E000111: Unable to connect to a repository at URL 'svn://svn.openwrt.org/openwrt/trunk'
svn: E000111: Can't connect to host 'svn.openwrt.org': Connection refused

然后张自然搜索得知已经永久关闭,全面替代为git方式。

http://www.right.com.cn/forum/thread-183974-1-1.html

openwrt-svn-off

在这里张自然为了简洁明了,真正让普通人也能看懂,只提供openwrt trunk方法,其余版本地址请见官网。

openwrt源码官方下载地址https://dev.openwrt.org/wiki/GetSource

原来openwrt svn服务器地址:svn co svn://svn.openwrt.org/openwrt/trunk trunk

 

 

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

cd trunk

./scripts/feeds update -a

./scripts/feeds install -a

因最近openwrt官网不稳定,提供国内备用svn地址:

svn://svn.openwrt.org.cn/openwrt/trunk

svn co svn://svn.openwrt.org.cn/openwrt/branches/backfire backfire

luci的源码镜像:

svn://svn.openwrt.org.cn/luci/luci/branches

svn://svn.openwrt.org.cn/luci/luci/trunk

 

(一般来说,虚拟机安装的ubuntu系统默认不是启用的root账户,所以可以跳过这一步。)

然后新建个普通用户,useradd代表新建用户,这里张自然新建的是zhangziran用户,当然你可以随意定义用户名。

之所以要新建用户是因为openwrt不允许在root用户下编译,如果编译会报错。具体原因张自然也不知道。

useradd zhangziran

为新建的用户指定root目录访问权限,一定要赋予openwrt源码所在根目录权限,这里张自然的在root目录下。否则后面还是会提示权限不足。

chown zhangziran /root/ -R

切换到zhangziran用户

su zhangziran

开始配置编译openwrt固件

当然你也可以加上--force强制安装,但张自然并不推荐这种方式,也许会产生什么未知错误呢。

下面进入定制界面(里面可以选择芯片的型号,集成的组件等等,根据实际情况选择)

如果还是报错请执行make defconfig,检查编译环境。并贴上错误到文章评论,张自然看到后会依据自身能力帮忙处理。

make menuconfig

openwrt-rootbaocuo

如果执行make menuconfig报以下错误顾名思义是指的是显示器太小,必须至少19行80列。张自然使用的putty遇到这个问题。只需要拉大putty窗口即可解决。使用虚拟机的同样操作也可以解决。

Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
/root/openwrt/trunk/include/toplevel.mk:115: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 1

进入菜单后我们从上到下依次选择架构、品牌、型号就好。

 

 

 

app源码目录:feeds/packages/net/

luci-app源码目录:/openwrt/feeds/luci/applications

比如我们下载了一个wifidog luci的源码,那么我们将luci-app-wifidog.zip解压到feeds/luci/applications目录下面,然后将wifidog目录下的wifidog.init 复制到 源码根目录feeds/packages/net/wifidog/files目录下面。

https://blog.kos.org.cn/OP/17.html

 

1.cc源码目录下的 feeds目录下的 luci.index文件内容后面追加如下代码,其实执行可以自动生成

./scripts/feeds update -a -i

./scripts/feeds install -a

 

Source-Makefile: feeds/luci/applications/luci-app-wifidog/Makefile
Package: luci-app-wifidog
Submenu: 3. Applications
Version: x-1
Depends: +libc +SSP_SUPPORT:libssp +USE_GLIBC:librt +USE_GLIBC:libpthread  +wifidog
Conflicts: 
Menu-Depends: 
Provides: 
Build-Depends: lua/host luci-base/host 
Section: luci
Category: LuCI
Title: LUCI wifidog module
Maintainer: 
Source: 
Type: ipkg
Description: LUCI wifidog module

@@

现在的环境是这个的。trunk源码下的feeds/packages/net/下没有autossh,我down了一份bb版的源码,make menuconfig的network/ssh/下可以看到autossh,所以我在bb源码目录的feeds/oldpackages/net/下看到了autossh,我于是把autossh这个文件夹 拷贝到了 trunk版feeds/packages/net/目录下,我如何才能make menuconfig看到相应的autossh?或者说我如何单独的编译这个autossh!
make package/autossh/compile

谢谢,您这句话的意思是添加到menuconfig中。我把autossh扔到了源码目录下的package目录下,用这个命令成功了。menuconfig中ssh中确实能够看到了。但是如果想直接编译出一个ipk应该怎么做?

 

 

 

 

https://downloads.openwrt.org/kamikaze/docs/openwrt.html

以下简单翻译为

如果你发现你的包在menuconfig中显示不出来,请执行:

TOPDIR=$PWD make -C package/<name> DUMP=1 V=99

如果你只是单独编译一个包,那么你可以直接执行快捷方式。

 

在OPENWRT下执行make menuconfig,然后选择Utilities -> gpioctl为<M>,保存退出就可以了

 

清理已经生成的ipk包

make package/<name>/clean V=99

安装

make package/<name>/install V=99

预配置

make package/<name>/prepare V=99

编译

make package/<name>/compile V=99

make package/wifidog/compile V=99

make luci/wifidog/compile V=99

配置

make package/<name>/configure V=99

2.1.5 Troubleshooting

If you find your package doesn’t show up in menuconfig, try the following command to see if you get the correct description:
TOPDIR=$PWD make -C package/<name> DUMP=1 V=99
If you’re just having trouble getting your package to compile, there’s a few shortcuts you can take. Instead of waiting for make to get to your package, you can run one of the following:

make package/<name>/clean V=99

make package/<name>/install V=99
Another nice trick is that if the source directory under build_dir/<arch> is newer than the package directory, it won’t clobber it by unpacking the sources again. If you were working on a patch you could simply edit the sources under the build_dir/<arch>/<source> directory and run the install command above, when satisfied, copy the patched sources elsewhere and diff them with the unpatched sources. A warning though - if you go modify anything under package/<name> it will remove the old sources and unpack a fresh copy.
Other useful targets include:

make package/<name>/prepare V=99

make package/<name>/compile V=99

make package/<name>/configure V=99

 

 

 

不编译安装luci

http://www.openwrt.org.cn/bbs/thread-15879-1-1.html

经过摸索,找到了一个非常简单的解决方案---------通过源码手动添加相应文件来实现ipk自动进行的操作。
首先确保安装了aria2,再找到luci-app-aria2的ipk包或源码包,然后解压得到需要的相关文件放置到对应的路径下面,完成后重启aria2服务即可。
下面说一下具体步骤:
1. 找到ipk包
luci-app-aria2.ipk

2. 将ipk包用uniextract161_noinst进行解压得到一个源码包
luci-app-aria2

解压工具:
http://legroom.net/scripts/download.php?file=uniextract161_noinst

3.ssh进入openwrt系统,将data包中的3个文件夹里面的文件按路径放到系统对应的地方。
注意,这里我只需要data包里面的文件,其他两个(control.tar.gz和debian-binary)就不要了。

4. 上面三步完成了之后,记得查看对应目录下其他文件的权限,改成一样的即可。

5. 重启,大功告成!非常简单的方法!

 

 

最后,执行make开始编译。剩下的就是等待了,第一次编译需要的时间相对比较长,这个跟你的电脑配置和网速有关。这也是张自然使用vps的一个原因。V=99表示输出详细的debug信息

make V=99

还有一种多线程变态编译方法,官方说是多核编译。这样做虽然编译速度更换但是容易出错,而且不容易找到出错原因。-j 代表多核编译,后面跟上核数。

@ryd994补充:多线程的话,要出错都是集中在tools部分,先make tools,然后再make -j cpu数+1~2就没问题了V=99没必要用,多线程跑,跑到后面如果出错了 就make 一下出错的,把出错部分单独编过去,然后继续多线程。如果单线程都不过,可以make 出错的部分/clean 再试,如果再不行再V=99。

make V=99 -j 5

关于首次编译时间,建议尽量开启vpn或者使用国外vps进行编译,否则速度绝对令人捉急。。。。

编译完成后,固件或者编译的ipk文件会生成在openwrt源码目录下bin文件夹。

编译一个单独的ipk软件包

make menuconfig配置Build the OpenWrt SDK,然后会在/bin/你的架构/目录下生成OpenWrt-SDKxxx。解压进入会看见一个package,把你需要编译的源码放到该目录。返回解压的目录make编译就可以了。

编译好的文件放置在bin/你的架构/package目录下

下面是openwrt编译界面汉化翻译:

M键表示编译成ipk但不会编译到固件里。需要的时候我们可以直接opkg install

空格键是选择,可以代替Y/N/M键的使用

/是搜索软件包。

openwrt-bianyi-fanyi

openwrt-bianyi-fanyi1

openwrt-bianyi-fanyi2

  1. 张自然个人博客
    openvz吗。。。。ramnode最近不知道超兽状态如何。。。换个xen的512m试试看呢。。。
  2. 366142
    感谢分享!但我在 RamNode VPS Ubuntu 14.04 32-bit 报错,如下

    i686-linux-gnu-g++: internal compiler error: Killed (program cc1plus)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
    make : *** [c_source.lo] Error 1
    make : Leaving directory `/root/openwrt/build_dir/host/gengetopt-2.22.6/src/skels'
    make : *** [all] Error 2
    make : Leaving directory `/root/openwrt/build_dir/host/gengetopt-2.22.6/src/skels'
    make : *** [all-recursive] Error 1
    make : Leaving directory `/root/openwrt/build_dir/host/gengetopt-2.22.6/src'
    make : *** [all] Error 2
    make : Leaving directory `/root/openwrt/build_dir/host/gengetopt-2.22.6/src'
    make : *** [all-recursive] Error 1
    make : Leaving directory `/root/openwrt/build_dir/host/gengetopt-2.22.6'
    make : *** [all] Error 2
    make : Leaving directory `/root/openwrt/build_dir/host/gengetopt-2.22.6'
    make : *** [/root/openwrt/build_dir/host/gengetopt-2.22.6/.built] Error 2
    make : Leaving directory `/root/openwrt/tools/gengetopt'
    make : *** [tools/gengetopt/compile] Error 2
    make : Leaving directory `/root/openwrt'
    make : *** [/root/openwrt/staging_dir/target-mips_34kc_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyyyyyyyyyyyynyyyyynnyyynyyynnnyy] Error 2
    make :Leaving directory `/root/openwrt'
    make :*** [world] Error 2

    请问各位有知道那里出错吗,还是VPS不给力,编译不出来的?
  3. 张自然个人博客
    哈哈,小名。http://www.zhangziran.com/about
  4. 华省省站长博客
    不错哦!张自然!艺名吧!
  5. 建站爱好者
    博主加油。我会陪伴你成长的
  6. 建站爱好者
    博主加油。我会陪伴你成长的
  7. 过客
    高手!支持你
  8. 斌斌
    自然兄. 我来了....

给张自然个人博客留言取消回复

Copyright © ZhangZiRan.com All Rights Reserved. 张自然个人博客 内容版权所有,同时保留所有权利。个人博客免责声明

用户登录