轉自:http://www.cnblogs.com/qiaoqiao2003/p/3738552.html
Debian系統本身包含對arm的支持,其包含的軟件包最多,但是最終的文件系統要大一些。
emdebian 是一個非常好用的嵌入式linux操作系統,其基於debian的特點對於熟悉debian系統的人來說很容易就能得心應手地進行配置。
emdebian有好幾個版本:Grip,Crush,Baked. 關於它們的詳細介紹可以查看:http://www.emdebian.org/emdebian/flavours.html
通常為了便於使用,我們選擇Grip版本。
debian下有三個工具可以用來創建根文件系統,它們分別是Debootstrap、CDebootstrap和Multistrap,安裝這幾個軟件:
apt-get install debootstrap multistrap
本文中內容主要參考debian網站的CrossDebootstrap。
先用Debootstrap制作基於debian根文件系統(詳見官方文檔):
debootstrap --foreign --arch armel wheezy rootfs http://ftp.debian.org/debian/
會在當前的rootfs下建立一個基本的根文件系統(名字為rootfs),然后將rootfs文件家移到nfs對應文件夾下,並重啟nfs:
/etc/init.d/nfs-kernel-server restart
啟動mini2440,按任意鍵進入uboot,按'q'鍵進入uboot命令行,將bootargs修改成以下內容:
noinitrd root=/dev/nfs rw nfsroot=192.168.211.2:/home/host/nfs/mini2440/rootfs ip=192.168.211.211 console=ttySAC0 init=/bin/bash
重啟mini2440,但是無法進入跟文件系統,提示下面的錯誤:
Warning: unable to open an initial console.
參考http://blog.chinaunix.net/uid-10008293-id-2972298.html ,在根文件系統下創建設備文件console和null:
cd rootfs/dev mknod -m 660 console c 5 1 mknod -m 660 null c 1 3
然后重啟mini2440,就可以進入根文件系統了。
然后在新的根文件系統下進行配置:
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C /debootstrap/debootstrap --second-stage
但是安裝base-file是提示出錯,查看/debootstrap/debootstrap.log才知道執行rmdir /var/run出錯。
用ls命令可以知道該文件夾下存在一個臨時文件,將該臨時文件刪除。然后再次執行上面的命令,但是在安裝 mount時提示下面的錯誤:
dpkg: error processing /var/cache/apt/archives/mount_2.20.1-5.3_armel.deb (--unpack):
然后就開始嘗試重新開始安裝這些deb包,默認情況下會重試5次才會停止執行。嘗試了半天,但是安裝過程中的錯誤很難追蹤和修正,
我最終放棄了使用debootstrap制作基於debian的根文件系統.
1.下面用debootstrap來安裝基於emdebian的根文件系統(參考文章http://www.linuxidc.com/Linux/2011-11/47804.htm):
步驟跟上面過程類似,先下載deb包:
debootstrap --foreign --arch armel --keyring=/usr/share/keyrings/emdebian-archive-keyring.gpg squeeze rootfs http://www.emdebian.org/grip
安裝qemu-user-static包,並將qemu-arm-static拷貝到rootfs下(該工具用於避免chroot出錯):
apt-get install qemu-user-static
cp /usr/bin/qemu-arm-static rootfs/usr/bin
然后安裝deb包:
chroot rootfs /bin/bash /debootstrap/debootstrap --second-stage
安裝過程中提示安裝dash出錯,執行”dpkg -i /var/cache/apt/archives/dash_0.5.5.1-7.4em1_armel.deb”可以得到下面的輸出信息:
(Reading database ... 3895 files and directories currently installed.) Unpacking dash (from .../dash_0.5.5.1-7.4em1_armel.deb) ... /bin/ln: creating symbolic link `/usr/share/man/man1/sh.1.gz.tmp': No such file or directory dpkg: error processing /var/cache/apt/archives/dash_0.5.5.1-7.4em1_armel.deb (--install): subprocess new pre-installation script returned error exit status 1 Errors were encountered while processing: /var/cache/apt/archives/dash_0.5.5.1-7.4em1_armel.deb
由於/usr/share/man文件夾不存在,所以無法創建軟鏈接,創建文件夾:
mkdir -p /usr/share/man/man1/
然后再次執行:
/debootstrap/debootstrap --second-stage
再執行下面的命令進行配置:
echo "deb http://www.emdebian.org/grip/ squeeze main" >> rootfs/etc/apt/sources.list printf "auto eth0\niface eth0 inet dhcp\n" >> /etc/network/interfaces
然后再將該采用nfs啟用根文件系統方式啟動mini2440,但是進入bash前有個錯誤提示:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell
這個問題暫時作為遺留問題,有空再來研究。
該文件系統大小在7、80M左右。
2.我下面選擇用CDebootsrap(用c語言開發的debootstrap類似工具,比debootstrap快很多)來制作基於debian的根文件系統,執行下面命令:
cdebootstrap --foreign --arch armel wheezy rootfs http://ftp.debian.org/debian/
然后仍然用nfs啟動根文件系統(選擇和上面一樣的bootargs),就能進入剛才制作的根文件系統。
然后用下面命令來完成deb包的解壓縮和安裝:
/sbin/cdebootstrap-foreign
然后執行下面的命令對所有未配置的deb包進行配置:
PATH=/usr/bin:/bin:/usr/sbin:/sbin dpkg --configure -a
現在基礎的一些配置就弄好了,當前rootfs大小在200多M左右。
整個過程非常流暢,沒有出現關鍵性錯誤導致安裝失敗的情況發生。
然后在對系統進行配置:
mount -t proc proc /proc route add default gw 192.168.211.1
然后再根據自己需要對/etc/apt/sources.list進行配置(可參考https://lug.ustc.edu.cn/repogen/)
3.接着使用CDebootstrap來制作基於emdebian的跟文件系統,執行下面的命令:
cdebootstrap --foreign --arch armel --keyring=/usr/share/keyrings/emdebian-archive-keyring.gpg squeeze rootfs http://www.emdebian.org/grip
但是顯示了下面的錯誤信息:
P: Retrieving InRelease P: Validating InRelease I: Good signature from "Emdebian Archive Signing Key" P: Parsing InRelease W: parser_rfc822: Iek! Don't find end of field, it seems to be after the end of the line! E: Couldn't parse InRelease!
所以后續過程也無法繼續下去了。
最后使用multistrap制作根文件系統。
先用multistrap制作基於debian的根文件系統:
創建配置文件,名稱為multistrap_debian.conf,內容如下:
[General] noauth=true unpack=true debootstrap=Squeeze aptsources=Squeeze arch=armel [Squeeze] packages=wpasupplicant wireless-tools firmware-ralink busybox netbase net-tools makedev source=http://ftp.au.debian.org/debian/ keyring=debian-archive-keyring components=main non-free suite=squeeze
然后執行下面的命令下載deb包並解壓縮:
multistrap -a armel -d rootfs -f multistrap_debian.conf
執行完畢后將qemu-arm-static拷貝到rootfs/usr/bin下
cp /usr/bin/qemu-arm-static rootfs/usr/bin
然后chroot進入rootfs,進行配置:
chroot rootfs touch /etc/fstab mount -t proc proc /proc dpkg --configure -a
然后在mini2440下設置nfs啟動根文件系統,配置與前面配置相同,但會有錯誤提示(不影響一般使用):
bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell
暫時作為遺留問題,留待解決。
整個文件系統大小在160M左右。
4.最后用multistrap制作基於emdebian的根文件系統。
先創建配置文件,名稱為multistrap_emdebian.conf,內容如下:
[General]
noauth=true
unpack=true
debootstrap=Grip
aptsources=Grip
[Grip]
# space separated package list
packages=busybox netbase net-tools ifupdown makedev
source=http://www.emdebian.org/grip
suite=squeeze
該文件中需要注意的是suite,suite類型有四種:etch,lenny,squeeze,sid分別對應oldstabe,stable,tesing,sid。
看名字基本能明白含義,只有sid不容易看明白,實際上sid表示滾動更新版本
執行下面命令制作根文件系統:
multistrap -a armel -d rootfs -f multistrap_emdebian.conf
很快就可以下載成功,並自動將deb包解壓縮根文件系統下。
將/usr/bin/qemu-arm-static拷貝到rootfs/usr/bin下,然后執行如下命令進行安裝后的配置:
chroot rootfs dpkg --configure -a
在配置過程中需要選擇時區,分別選擇6(Asia)和65(Shanghai).
重啟mini2440,采用nfs啟動根文件系統(和本文前面的配置一樣),但仍然會有一個錯誤(不影響一般使用):
bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell
這個問題仍然留待后續再解決。
生成根文件系統大小在50M左右
從前面陳述的根文件系統制作過程可以看到,mutlstrap比較利於擴展,使用也比較方便,所以我傾向於以后采用multistrap來制作根文件系統