Openwrt中文手冊

維基教科書,自由的教學讀本

OpenWRT中文手冊

引言[編輯]

本文是OpenWRT源碼手冊的中文譯本。可以通過版本控制工具SVN或者GIT來得到OpenWRT的源碼,命令如下: svn co svn://svn.openwrt.org/openwrt/branches/8.09 git://nbd.name/openwrt.git 下載完源碼後,需要進入docs目錄編譯生成pdfhtml格式的英文文檔。命令如下:
# cd docs
# make
當前目錄下的openwrt.pdf和openwrt.html即為生成的最終文件。

第一章 路由器設置簡介[編輯]

1.1 快速開始[編輯]

1.1.1 安裝[編輯]

1.1.2 初始化設置[編輯]

1.1.3 安全模式[編輯]

1.2 配置OpenWrt[編輯]

1.2.1 網絡[編輯]

第二章 開發指南[編輯]

2.1 系統結構[編輯]

2.1.1 構造鏡像[編輯]

OpenWrt選擇了另一種方式來生成固件:下載,打補丁,編譯,一切從零開始,即使交叉編譯鏈也是如此。

下載OpenWrt[編輯]

本文僅針對OpenWrt的Kamikaze分支編寫,可以使用如下subversion命令下載代碼:
$ svn checkout svn://svn.openwrt.org/openwrt/trunk kamikaze
另外,還有一個trac顯示界面[1],可以用它來瀏覽通過svn進行的提交和代碼。

目錄結構[編輯]

有四個關鍵的頂層目錄:

  • tools
  • toolchain
  • package
  • target

toolstoolchain包含了一些通用命令,用來生成固件、編譯器、和C庫。生成結果會儲存在以下三個目錄下:build dir/host是一個臨時目錄,用來儲存不依賴於目標平台的工具,build dir/toolchain-<arch>*用來儲存依賴於指定平台的編譯鏈,staging dir/toolchain-<arch>*是編譯鏈的最終安裝位置。通常你不需要改動編譯鏈目錄下的任何東西,unless you intend to add a new version of one of the components above.

  • build dir/host
  • build dir/toolchain-<arch>*

package——包。在OpenWrt固件中,幾乎所有東西都是.ipk,這樣就可以很方便的安裝和卸載。注意:這些包不是在主分支中維護的,但是可以使用package feeds系統通過subversion來獲取他們。
$ ./scripts/feeds update
這些包能夠擴展基本系統的功能,只需要將他們連結進入主幹。之後,這些包將會顯示在配置菜單中。對於kamikaze,你可以使用這樣的命令:
$ ./scripts/feeds search nmap
Search results in feed 'packages':
nmap Network exploration and/or security auditing utility
$ ./scripts/feeds install nmap
如果想包含所有的包,可以使用如下命令:
$ make package/symlinks
目標系統指嵌入式設備,針對不同的平台有不同的特性。針對這些特性,"target/linux"目錄下按照平台<arch>進行目錄劃分,裡面包括了針對標準內核的補丁,特殊配置等。There's also the "target/image" directory which describes how to package a firmware for a specific platform.
target and package兩部分都需要"build dir/<arch>"作為編譯的臨時目錄。另外,編譯鏈,目標平台,包要下載的東西都放在dl目錄下。

  • build dir/<arch>
  • dl

2.3 使用Openwrt[編輯]

以下的段落將會介紹一些技巧,可以提高日常工作的效率。

2.3.1 編譯/重編譯組件[編輯]

buildroot可以很方便的重編譯整個系統,也可以只編譯某個部分,比如工具鏈、內核模塊、內核和軟件包等。
如果你做了一些修改,然後想重編譯工具鏈,可以執行如下命令:
make toolchain/{clean,compile,install}
它將會clean, compile and install工具鏈,將會顯示如下:
make[1] toolchain/clean
make[2] -C toolchain/kernel-headers clean
make[2] -C toolchain/binutils clean
make[2] -C toolchain/gcc clean
make[2] -C toolchain/uClibc clean (glibc or eglibc when chosen)
當然,你也可以分開編譯工具鏈的幾個部分(binutils, kernel-headers gcc, C library)。
可以用同樣的方法編譯軟件包。
make package/busybox/{clean,compile,install}

will clean, compile and install buysbox (if selected to be installed on the final rootfs).

Supposing that you made changes to the Linux kernel, but do not want to recompile everything, you can recompile only the kernel modules by issuing:

make target/linux/compile To recompile the static part of the kernel use the following command: make target/linux/install

2.3.2 使用OpenWrt內部的quilt[編輯]

OpenWrt integrates quilt in order to ease the package, kernel and toolchain patches maintenance when migrating over new versions of the software.

Quilt intends to replace an old workflow, where you would download the new source file, create an original copy of it, an a working copy, then try to apply by hand old patches and resolve conflicts manually. Additionnaly, using quilt allows you to update and fold patches into other patches easily.

Quilt is used by default to apply Linux kernel patches, but not for the other components (toolchain and packages).

附件[編輯]

OpenWrt英文手冊