现在的位置: 首页 > 综合 > 正文

根文件系统制作 (一)

2013年10月21日 ⁄ 综合 ⁄ 共 3806字 ⁄ 字号 评论关闭

根据busybox源码可知,最小的根文件系统要具备如下条件:

1./dev/console 和/dev/null(open()打开设备)

2.init(来源于busybox,主要是一些命令,如cp,ls等,等编译busybox时,就得到)

3./etc/inittab

4.配置指定的程序

5.C库(r如:标准输入,输出,错误等)

 

【环境】

1:Ubuntu 10.10

2:u-boot-2010.03

3:linux-2.6.35

4:busybox-1.17.3

5:优龙FS2410

6:交叉编译器:arm-none-linux-gnueabi-gcc version 4.3.2


1)解压缩busybox

tar xjvf busybox-1.17.3.tar.bz2

 解压后,可以在当前busybox目录下,看INSTALL或README,教你如何编译

2)配置源码

tony@Ubuntu:~/win/busybox-1.17.3$make menuconfig

BusyboxSettings  --->

        BuildOptions  --->

                [*] BuildBusyBox as a static binary (no shared libs)

                [ ] Force NOMMU build (NEW)

                [ ] Build with Large File Support (foraccessing files > 2 GB)

                (/home/tony/toolchain/bin/arm-none-linux-gnueabi-)Cross Compiler prefix

                ()  Additional CFLAGS (NEW)

 

3)编译

tony@Ubuntu:~/win/busybox-1.17.3$make

 

4)安装

busybox默认安装路径为源码目录下的_install

但是最好不要用默认目录,不然很容易破坏我们得东西,组号再创建一个目录

tony@Ubuntu:~/win/busybox-1.17.3$ mkdir
-p /win/first_fs

tony@Ubuntu:~/win/busybox-1.17.3$ make CONFIG_PREPIX=/win/first_fs/install    根据busybox就可知道

tony@Ubuntu:~/win/busybox-1.17.3$  cd win/first_fs/install   

tony@Ubuntu:~/win/busybox-1.17.3$make install


5)进入安装目录tony@Ubuntu:~/win/busybox-1.17.3/_install$ls

bin  linuxrc sbin  usr

-------------------------------------------------------------------------------

上面则实现了busybox编译,也可以用一些命令了(如;ls ,cp等)

----------------------------------------------------------------------------


 

6)添加其他所需目录 

tony@Ubuntu:~/win/busybox-1.17.3/_install$mkdir dev etc mnt proc var tmp sys root lib

 

7)添加库

tony@Ubuntu:~/win/busybox-1.17.3/_install/lib$cp /home/tony/toolchain/arm-none-linux-gnueabi/lib/*so* ./lib/ -a

 

8)在管理员模式对库瘦身

tony@Ubuntu:~/win/busybox-1.17.3/_install$sudo su

root@Ubuntu:/home/tony/win/busybox-1.17.3/_install#source /home/tony/.bashrc            //如果在etc/profile中不用

root@Ubuntu:/home/tony/win/busybox-1.17.3/_install#arm-none-linux-gnueabi-strip./lib/*

root@Ubuntu:/home/tony/win/busybox-1.17.3/_install#exit

 

9)添加系统启动文件

tony@Ubuntu:~/win/busybox-1.17.3/_install/etc$vim inittab

添加如下内容:

#this is run first except when booting insingle-user mode.

::sysinit:/etc/init.d/rcS

# /bin/sh invocations on selected ttys

 

# Start an "askfirst" shell on theconsole (whatever that may be)

::askfirst:-/bin/sh

 

# Stuff to do when restarting the init process

::restart:/sbin/init

 

#Stuff to do before rebooting

::ctrlaltdel:/sbin/reboot

 

10)在etc下添加fstab

tony@Ubuntu:~/win/busybox-1.17.3/_install/etc$vim fstab

添加如下内容:

#device    mount-point     type options     dump        fsch order

proc /proc         proc defaults   0       0

tmpfs        /tmp         tmpfs        defaults   0       0

sysfs         /sys  sysfs         defaults   0       0

tmpfs        /dev tmpfs        defaults   0       0

 

11)这里我们挂载的文件系统有三个:proc、sysfs和tmpfs,在内核中proc和sysfs默认都支持,

而tmpfs是没有支持的,检查内核有没有支持tmpfs,如果没有请设置

tony@Ubuntu:~/win/linux-2.6.35$make menuconfig

File systems  --->

        Pseudo filesystems  --->

                [*] Virtual memory file system support(former shm fs)

                [*]   Tmpfs POSIX Access Control Lists

重新编译内核


12)在etc下创建init.d目录,并在该目录下创建rcS文件 

tony@Ubuntu:~/win/busybox-1.17.3/_install/etc$mkdir init.d

tony@Ubuntu:~/win/busybox-1.17.3/_install/etc/init.d$vim rcS

添加如下内容:

#!/bin/sh

#This is the firstscript called by init process

/bin/mount -a

 为rcS添加可执行权限

tony@Ubuntu:~/win/busybox-1.17.3/_install/etc/init.d$chmod +x rcS

 

13)在etc下创建profile文件

tony@Ubuntu:~/win/busybox-1.17.3/_install/etc$vim profile

添加如下内容:

#!/bin/sh

exportHOSTNAME=tony

export USER=root

export HOME=root

#exportPS1="[$USER@$HOSTNAME \W]#"

PATH=/bin:/sbin:/usr/bin:/usr/sbin

LD_LIBRARY_PATH=lib:/usr/lib:$LD_LIBRARY_PATH

export PATHLD_LIBRARY_PATH

 

14)在dev下创建console节点(这个设备节点是必须

tony@Ubuntu:~/win/busybox-1.17.3/_install$sudo mknod dev/console c 5 1

 

15)制作已完成,在NFS中进行测试

①将OK的文件系统拷贝到/opt/filesystem下

tony@Ubuntu:~/win/busybox-1.17.3$cp _install/* /opt/filesystem -a

②设置U-Boot环境变量

setenv bootcmd tftp 30800000 uImage \; bootm

setenv bootargs console=ttySAC0,115200 init=/linuxrc root=nfs nfsroot=192.168.7.103:/opt/filesystem ip=192.168.7.163

重新启动开发板,查看是否能够正常挂载

抱歉!评论已关闭.