debian下为arm开发板创建基于debian或emdebian的根文件系统

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的根文件系统.

 

下面用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左右。

 

我下面选择用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/

 

接着使用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左右。

 

最后用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来制作根文件系统

 

 

posted on 2014-05-21 10:01  qiaoqiao2003  阅读(6793)  评论(0编辑  收藏  举报

导航