轉自:http://www.cnblogs.com/qiaoqiao2003/p/3738552.html
轉自:http://blog.csdn.net/luoqindong/article/details/42737879
debootstrap: https://wiki.debian.org/Debootstrap
multistrap: https://wiki.debian.org/Multistrap
cross-debootstrapping: https://wiki.debian.org/EmDebian/CrossDebootstrap
cdebootstrap: https://wiki.debian.org/cdebootstrap
debian系統有針對arm分支的,在arm上跑debian系統可以用apt-get安裝軟件,避免繁瑣的編譯和重復創建文件系統的工作.
本例子使用z-turn的開發板為例.
linux主機版本:
root@v:i# lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 7.7 (wheezy) Release: 7.7 Codename: wheezy
1. 安裝 qemu 和 debootstrap 等工具
$ sudo apt-get install binfmt-support qemu qemu-user-static debootstrap multibootstrap
debootstrap ---- 一個 Debian 提供的工具,可以用來生成指定構架的文件系統
qemu ---- 用於模擬 arm 環境
2. 用 debootstrap 抽取基本系統(從 debian 源中下載)
在opt下創建文件系統目錄fs_debian_wheezy
$sudo debootstrap --arch=armel --foreign wheezy fs_debian_wheezy http://cdn.debian.net/debian(http://ftp.debian.org/debian/)
arch指定了cpu架構, wheezy指定Debian系統代號,可在網上找不同的debian版本對應的代號.
上面的命令我這邊要運行2次,
第一次出現這樣的信息:
I: Retrieving libxapian22 I: Validating libxapian22 I: Retrieving liblzma5 I: Validating liblzma5 I: Retrieving xz-utils I: Validating xz-utils I: Retrieving zlib1g I: Validating zlib1g
下載的時候有些warning, 提示有些庫下載不了,這個不影響.
第2次是這樣的信息:
I: Extracting bsdutils... I: Extracting libblkid1... I: Extracting libmount1... I: Extracting libuuid1... I: Extracting mount... I: Extracting util-linux... I: Extracting liblzma5... I: Extracting xz-utils... I: Extracting zlib1g...
從信息上看,第一次是從網上下載,第二次是將文件抽取出來,第2次之后,在fs_debian_wheezy目錄下才有bin,sbin等linux文件系統目錄.
3. 抽取完畢進行第二階段
因為在宿主是 x86 架構,不能安裝 arm 架構的軟件。需要依靠 qemu-arm-static 來
模擬成 arm 環境進行安裝。
- 復制 qemu-arm-static 到剛構建的基本系統中
$ sudo cp /usr/bin/qemu-arm-static fs_debian_wheezy/usr/bin
- 用 qemu-arm-static 來模擬 arm
$ sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot fs_debian_wheezy debootstrap/debootstrap --second-stage
該命令意思是設置一些環境變量,然后切換根目錄到fs_debian_wheezy,執行目錄fs_debian_wheezy/debootstrap下的命令: debootstrap --second-stage.
終端上會最后打印 I: Base system installed successfully.,說明根文件系統就定制成功了。
4. 修改文件,目錄等
$sudo cd fs_debian_wheezy $sudo echo "proc /proc proc defaults 0 0" >> etc/fstab $sudo mkdir -p usr/share/man/man1/ 如果dev/console設備節點不存在,也需要創建 $sudo mknod dev/console c 5 1
5.收尾工作
- 切換到 qemu
$sudo chroot fs_debian_wheezy
- 設置軟件源頭
# vi /etc/apt/source.list deb http://cdn.debian.net/debian wheezy main contrib non-free deb-src http://cdn.debian.net/debian wheezy main contrib non-free # apt-get update 更新軟件
- 為 root 設置密碼和創建新用戶
# passwd root
debian不能以root用戶登陸,所以創建一個普通用戶,登陸系統后再切換到root用戶
# adduser qq
# passwd qq 設置用戶i的密碼
- 修改 inittab, 打開串口終端
# cp /usr/share/usr/share/sysvinit/inittab /etc/
# vi /etc/inittab
找到 #T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100,大約在 63 行左右
修改為 T0:23:respawn:/sbin/getty -L ttyPS0 115200 vt100,此處依據自己的實際情況修改
- 退出 qemu 環境
# exit
6.制作完成
至此,一個基本的根文件系統就訂制完了。把根文件系統拷貝到SD卡上,插到ARM板上,
設置z-turn從SD卡加載根文件系統,如果一切順利一個debian 系統就運行起來了。
可以用apt-get 命令安裝各種軟件包,再也不用繁瑣的交叉編譯工作了。