您的位置:首页 > 运维架构 > Linux

[Linux驱动开发] 根文件系统制作

2012-03-19 20:15 573 查看
 

根文件系统制作

1下载busybox

Busybox下载地址:http://www.busybox.net/



 

2 解压 配置 编译busybox 

解压

terry@terry-virtual-machine:/opt/filesystem$ ls busybox-1.18.5.tar.bz2

busybox-1.18.5.tar.bz2

terry@terry-virtual-machine:/opt/filesystem$ sudo tar xvf busybox-1.18.5.tar.bz2

terry@terry-virtual-machine:/opt/filesystem$ ls

busybox-1.18.5  busybox-1.18.5.tar.bz2



配置  

进入busybo-1.18.5目录  make menuconfig



进入Busybox Settings --->



进入Build Configuration -->



配置Cross Compiler prefix



为开发板设置编译器前缀 arm-linux-gnu-



保存后

编译 make  

发现错误 :



改错:把ionice去掉

怎样去掉呢?

在make menuconfig中:/ionice,寻找ionice



发现ionice在Locations:--> Miscellaneous Utilities



退回主菜单页面Busybox Configuration寻找Miscellaneous Utilities



去掉ionice选项



修改networking/libiproute/ipaddress.c

vi networking/libiproute/ipaddress.c



把下面这个



改成下面这个



再编译 make   结果通过

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5$ make install

得到目录_install



terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5$ mkdir first_fs

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5$ cp _install/* first_fs/ -rf



terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5$ cd first_fs/

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ mkdir etc

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ vi etc/inittab

bosybox的init进程会展开/etc/inittab,根据打开文件是设置来启动其他程序

busybox的inittab文件的格式: 

  <控制台>::<动作>:<要启动的脚步或程序> 



terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs/etc$ mkdir init.d

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs/etc$ vi init.d/rcS



给有需要的文件rcS加执行权限

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ mkdir lib

从交叉编译工具链下面复制库::

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$cp/opt/toolchains/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/arm-linux-gnu/lib/*so* ./lib/ -d

完善文件系统:

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ mkdir sys

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ mkdir proc

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ mkdir dev

在/dev目录下面创建console文件

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs$ sudo mknod dev/console c 5 1

从网络文件nfs挂载根文件系统:

系统启动时,在挂载文件系统前,修改u-boot的参数(这里的u-boot是之前已经做好的,我们所需要的仅仅是在u-boot启动后要加载文件系统时,重新设定u-boot加载的文件系统路径,即,将我们刚刚做好的first_fs文件路径加载到u-boot加载文件的路径当中):

set bootargs root=nfs nfsroot=192.168.7.153:/opt/filesystem/busybox-1.18.5/first_fs console=ttySAC0,115200 ip=192.168.7.253

然后,boot,这样u-boot就会到指定的文件路径中去加载文件系统



这样,最简单的网络挂载根文件系统成功



另外,这里需要特别注意的是,每当我们创建一个文件系统之后,我们需要将这个文件系统放到export中,这样系统才能够识别并加载这个文件系统

具体方法是:sudo vi /etc/exports,添加自己的文件系统



这样的文件系统可以添加很多,但是每次添加之后不要忘记重启:

sudo /etc/init.d/nfs-kernel-server restart

sudo exportfs -a

这里我们还可以编写一个hello应用程序,交叉编译后,把它放到/opt/rootfs/usr/bin下面,并修改权限为777

terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs/etc/init.d$ vi rc.local

/usr/bin/hello &



terry@terry-virtual-machine:/opt/filesystem/busybox-1.18.5/first_fs/etc$ vi init.d/rcS



系统启动后就会自动执行hello程序

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息