官方支持硬件列表

http://wiki.openwrt.org/toh/start

1、先下载Ubuntu 12.04LTS:

http://gb.releases.ubuntu.com//precise/ubuntu-12.04.2-desktop-i386.iso


2、装系统,不会装的话google去在安装过程中记得创建一个openwrt用户


3、开启root用户的步骤以及开机挂载dl磁盘步骤

①开启root用户

sudo passwd root

②开机挂载dl文件磁盘,需要切换到root用户下执行命令

mkdir /media/dl
chown openwrt:openwrt /media/dl -R
vim /etc/fstab

  增加如下一行:

/dev/sdb1   /media/dl     ext4    defaults        0       2


4、配置本地软件包,节约到网上下载的时间

①备份

cp /var/cache/apt/archives/*.deb /media/dl/deb/

②恢复

cp /media/dl/deb/*.deb /var/cache/apt/archives/
apt-get update
cd /home/openwrt/trunk/dl/deb/
dpkg -i *.deb
cd /var/cache/apt/archives/
ln -s /media/dl/deb archives

5、安装一些依赖库和编译工具

官方的安装库和依赖如下:

参考:http://wiki.openwrt.org/zh-tw/doc/howto/buildroot.exigence

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

民间的安装库和依赖如下:

参考:http://www.right.com.cn/forum/forum.php?mod=viewthread&tid=119876&page=1&extra=#pid712981

sudo apt-get install g++ libncurses5-dev zlib1g-dev bison flex unzip autoconf gawk make gettext gcc binutils patch bzip2 libz-dev asciidoc subversion sphinxsearch libtool sphinx-common

我两个都安装了,因为我经常遇到依赖库安装不全编译报错的情况。


6、下载源码

参考:

https://dev.openwrt.org/wiki/GetSource

https://dev.openwrt.org.cn/wiki/GetSource

svn checkout svn://svn.openwrt.org/openwrt/trunk/
svn update


7、更新下载扩展软件包

参考:http://wiki.openwrt.org/zh-tw/doc/howto/build#更新.feeds

cd trunk/
./scripts/feeds update -a
./scripts/feeds install -a


8、开始定制需要的模块

参考:

https://dev.openwrt.org.cn/wiki/howto

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

http://hi.baidu.com/hackmicrosoft/item/323dc2bec6777bf562388ede


make menuconfig


Ubuntu 12.04.2 LTS下编译华硕RT-N13U B1路由器OpenWrt固件_嵌入式Linux


需要注意的是Target Profile一定要选Default Profile,因为你选华硕RT-N13U出不了固件的


如果在选择模块的时候遇到去不掉,选不上的情况

请第一遍选择完了之后再回过头来选择或者去掉就可以了

因为组件有依赖关系的,我写的笔记没有按依赖关系来写,而是按步骤来写的

添加软件包,注意如果不熟悉编译的话默认选择的最好不要删除,根据自己的需要增加即可


01、选择CPU型号

Target System    --->    Ralink RT288x/RT3xxx

02、选择CPU子型号

Subtarget    --->    RT3x5x/RT5350 based boards

03、不集成IPV6包    

Global build settings    --->    Enable IPv6 support in packages

04、添加USB挂载

Base system    --->    block-mount

05、添加WEB界面,中文支持,根据需要选择app,这里需要注意的是可能会出现没有ushare可选,那是因为还有一个libffmpeg-mini没有选择我会在后面来选择。

LuCI    --->    Themes    --->    luci-theme-openwrt
LuCI    --->    Collections    --->    luci
LuCI    --->    Translations    --->    luci-i18n-chinese
LuCI    --->    Applications    --->    luci-app-ddns
LuCI    --->    Applications    --->    luci-app-hd-idle
LuCI    --->    Applications    --->    luci-app-multiwan
LuCI    --->    Applications    --->    luci-app-p910nd
LuCI    --->    Applications    --->    luci-app-qos
LuCI    --->    Applications    --->    luci-app-samba
LuCI    --->    Applications    --->    luci-app-upnp
LuCI    --->    Applications    --->    luci-app-ushare
LuCI    --->    Applications    --->    luci-app-wol

06、添加ext4磁盘格式支持

Kernel modules    --->    Filesystems    --->    kmod-fs-ext4

07、添加UTF8支持


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

08、禁用kmod-ipv6


Kernel modules    --->    Network Support    --->    kmod-ipv6

09、添加pptp,l2tp支持


Kernel modules    --->    Network Support    --->    kmod-pppol2tp
Kernel modules    --->    Network Support    --->    kmod-pptp

10、添加USB支持


Kernel modules    --->    USB Support    --->    kmod-usb2
Kernel modules    --->    USB Support    --->    kmod-usb-storage
Kernel modules    --->    USB Support    --->    kmod-usb-storage-extras
Kernel modules    --->    USB Support    --->    kmod-usb-printer

11、添加aria2下载工具


Network    --->    File Transfer    --->    aria2

12、禁用ip6tables

Network    --->    Firewall    --->    ip6tables

13、添加通用UNIX打印系统语言环境


Network    --->    Printing    --->    cups-locale-zh

14、添加PPTPD服务支持


Network    --->    ×××    --->    pptpd

15、禁用6relayd


Network    --->    6relayd

16、禁用odhcp6c


Network    --->    odhcp6c

17、禁用libip6tc


Libraries    --->    Firewall    --->    libip6tc

18、添加libffmpeg-mini支持ushare需要



Libraries    --->    libffmpeg-mini


19、添加lrzsz上传下载工具支持(非常实用)


Utilities    --->    lrzsz

20、添加自动挂载工具


Utilities    --->    Filesystem    --->    badblocks

21、添加fdisk分区工具


Utilities    --->    disc    --->    fdisk

22、添加reset键支持(长按5秒以上就可以恢复固件默认设置)


Utilities    --->    restorefactory

23、添加一键开关无线(按一下WPS键放开无线就打开或者关闭)

Utilities    --->    wifitoggle

24、选择完了之后就保存然后退出


9、编译固件


   因为我是用的VMware虚拟机编译的,所以的专门用了一块磁盘(dl)来存放编译时下载的文件,下次换系统编译时同样可以挂载上去使用不需要再联网下载已有文件了,很方便!


把dl磁盘软链接到/home/openwrt/trunk/dl

ln -s /media/dl /home/openwrt/trunk/dl


删除软链接的方法

rm /home/openwrt/trunk/dl -rf


创建一个和问题固件名称相同的文件用以跳过编译失败,从而导致编译暂停!

mkdir /home/openwrt/trunk/bin/ramips/ -p
touch /home/openwrt/trunk/bin/ramips/openwrt-ramips-rt305x-whr-g300n-squashfs-sysupgrade.bin


最好拨号到国外的×××然后编译这样才不会因为GFW的原因导致编译出错、这里谢谢一下baohua.me提供的×××Ubuntu 12.04.2 LTS下编译华硕RT-N13U B1路由器OpenWrt固件_嵌入式Linux_02


Ubuntu设置×××图:

Ubuntu 12.04.2 LTS下编译华硕RT-N13U B1路由器OpenWrt固件_rt-13u_03

Ubuntu 12.04.2 LTS下编译华硕RT-N13U B1路由器OpenWrt固件_openwrt_04

登录成功会出现如下图

Ubuntu 12.04.2 LTS下编译华硕RT-N13U B1路由器OpenWrt固件_嵌入式Linux_05


编译

cd ~/trunk/
make -j 5 V=s


   说明,-j 5的意思是5个任务同时进行,官方wiki给出的建议是cpu+1。V=s是显示详细编译过程!

完了之后会在/home/openwrt/trunk/bin/ramips/生成对应的固件,我的路由器是RT-N13U B1所以对应的固件是

openwrt-ramips-rt305x-rt-n13u-squashfs-sysupgrade.bin


编译完了可以执行如下命令


清除(刪除bin和build_dir目录內容。)

make clean


清除目录(除了刪除bin和build_dir的內容,并且包含staging_dir和toolchain(跨平台编译的工具),Dirclean是基本的清除指令)

make dirclean


清除编译(消灭所有的已编译的部分或设定,並刪除以下载的套件和源码)

make distclean

注意: 请小心使用,这个命令会移除你的配置設定(.config),toolchain和其他所有的源码!



补充内容:

禁用IPV6内核

vim package/base-files/files/etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

修改默认密码

vim package/base-files/files/etc/passwd
root:$1$wEehtjxj$YBu4quNfVUjzfv8p/PBo5.:0:0:root:/root:/bin/ash

增加开机启动关闭LED灯,以及aria2启动脚本

vim package/base-files/files/etc/rc.local
#swconfig dev rt305x port 0 set led 11
#swconfig dev rt305x port 1 set led 11
#swconfig dev rt305x port 2 set led 11
#swconfig dev rt305x port 3 set led 11
#swconfig dev rt305x port 4 set led 11
#swconfig dev rt305x set apply
#aria2c --conf-path=/etc/config/aria2.conf -D