Chinaunix首页 | 论坛 | 博客
  • 博客访问: 560338
  • 博文数量: 252
  • 博客积分: 1068
  • 博客等级: 少尉
  • 技术积分: 1775
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-05 21:33
文章分类

全部博文(252)

文章存档

2013年(21)

2012年(231)

分类:

2012-05-23 20:36:30

嵌入式Linux文件系统()

BusyBox制作嵌入式文件系统

 

蒋冬冬

blog.yesky.com/blog/langboy

 

 

版权所有,蒋冬冬,200810

 

 

一、BusyBox的配置、编译和安装

Busybox已经有很多版本了,现在最新的版本是1.9.X但是要注意的一点是,busybox的各个版本在编译的时候与交叉编译器的库版本是有很大关联的。

本人现在采用busybox1.00-pre0版本,交叉编译器为armlinux2.95.3

Make menuconfig

根据自己配置的需要来选择busybox提供的功能。

这里不再一一介绍配置菜单的意思,仅简要贴出部分选项:

编译遇到问题请参考《busybox编译备忘录》

 

Busybox配置如下:

Busybox Settings >

General Configuration >

[*] Support for devfs /* 这个选项在1.0.0版本上有,在1.2.2版本上已经取消了 */

Build Options >

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

[*] Do you want to build BusyBox with a Cross Compiler?

(/usr/local/arm/3.4.1/bin/armlinux)

/* 该交叉编译路径的修改在Config.in文件301 */

Init Utilities >

[*] init

[*] Support reading an inittab file

/* 支持init读取/etc/inittab配置文件,一定要选上 */

Shells >

Choose your default shell (ash) >

/* (X) ash 选中ash,这样生成的时候才会生成bin/sh文件

* 看看我们前头的linuxrc脚本的头一句:

* #!/bin/sh 是由bin/sh来解释执行的

*/

[*] ash

Coreutils >

[*] cp

[*] cat

[*] ls

[*] mkdir

[*] echo (basic SuSv3 version taking no options)

[*] env

[*] mv

[*] pwd

[*] rm

[*] touch

Editors >

[*] vi

Linux Module Utilities>

[*] insmod

[*] rmmod

[*] lsmod

[*] modprobe

Linux System Utilities >

[*] mount

[*] umount

[*] Support loopback mounts

[*] Support for the old /etc/mtab file

/* 注意不要选择支持2.4内核,选上的话,会出现编译错误 */

编译make

安装make install

/* 这个时候在目录下可以看见arm_install目录,该目录就是我们所需要的,因为本人选择生成目录为./ arm_install*/

 

二、文件系统目录的构建

cd    /

# create $ROOTFS structure

mkdir $ROOTFS

cd    $ROOTFS

# create dir

mkdir bin dev etc lib proc sbin tmp usr var lost+found

chmod 1777 tmp

mkdir usr/bin usr/lib usr/sbin

mkdir var/lib var/lock var/log var/run var/tmp

chmod 1777 var/tmp

echo "create $ROOTFS structure success!"

 

三、建立结点文件(设备文件)

# make node file in dev dir

cd $ROOTFS/dev

mknod console c 5 1

mknod full c 1 7

mknod kmem c 1 2

mknod mem c 1 1

mknod null c 1 3

mknod port c 1 4

mknod random c 1 8

mknod urandom c 1 9

mknod zero c 1 5

for i in `seq 0 7`;do mknod loop$i b 7 $i;done

for i in `seq 0 9`; do mknod ram$i b 1 $i;done

ln -s ram1 ram

mknod tty c 5 0

for i in `seq 0 9`; do mknod tty$i c 4 $i;done

for i in `seq 0 9`; do mknod vcs$i b 7 $i;done

ln -s vcs0 vcs

for i in `seq 0 9`; do mknod vcsa$i b 7 $i;done

ln -s vcsa0 vcsa

echo "make $ROOTFS/dev node success!"

 

四、建立脚本应用程序

# create linuxrc file

cd $ROOTFS/

touch $LINUXRC

chmod 775 $LINUXRC

echo "#\!/bin/sh" >> $LINUXRC

echo "# " >> $LINUXRC

echo "# create by do2jiang , 2008.10"  >> $LINUXRC

echo "# do2jiang@gmail.com" >> $LINUXRC

echo "#" >> $LINUXRC

echo "echo "Hello linux\! Helo World\!"" >> $LINUXRC

echo "exec /sbin/init" >> $LINUXRC

echo "create $ROOTFS/$LINUXRC success!"

 

五、拷贝运行时库

# copy lib file for rootfs from environment of CROSS-COMPILER

# this is "/usr/local/arm/2.95.3/arm-linux/lib"

cd $CROSS_COMPILER_LIB

 

for file in libc libcrypt libdl libm libpthread libresolv libutil;do cp $file-*.so  $ROOTFS/lib;cp -d $file.so.[*0-9]  $ROOTFS/lib;done

 

cp -d ld*.so* $ROOTFS/lib

echo "copy $ROOTFS/lib success!"

 

六、拷贝Applet 及其 etc配置文件

# copy file in dir of  bin/ and sbin/

cd $ROOTFS/

cp -a $BUSYBOX_ARMINSTALL/* $ROOTFS/

echo "copy busybox applet success!"

 

###################################################

# copy system config file to $ROOTFS/etc dir

# etc dir is in $BUSYBOX_INSTALL/etc,haved been copied.

echo "copy system etc file success!"

#本文已经将需要的配置文件,放在 $BUSYBOX_INSTALL/etc

###################################################


七、制作文件系统镜像

# make img file

cd /

mkdir $ROOTIMAGE

dd if=/dev/zero of=$IMAGENAME bs=1k count=9216

mke2fs -F -v -m0 $IMAGENAME

mount -o loop $IMAGENAME $ROOTIMAGE

 

#remove symble information

arm-linux-strip $ROOTFS/lib/*

                                                                                                                                                                           

cp -a  $ROOTFS/* $ROOTIMAGE/

umount $ROOTIMAGE

gzip -9 $IMAGENAME

echo "create $IMAGENAME file success!"

                                                                                      

#copy image file to DOWNLOAD PATH

cd /

cp $IMAGENAME.gz $DOWNLOADPATH

echo "copy file to $DOWNLOADPATH"

echo "ALL SET!"

 

 

八、测试文件系统

对制作的文件系统进行测试,本文制作的系统简单测试如下,显示制作是成功的!如图1所示。

 

 

图1.BusyBox V1.00-pre10制作的ramdisk文件系统测试截图

 

=====================制作镜像文件完全脚本如下====================

#

# !bin/bash

# create by do2jiang ,2008,10

# do2jiang@gmail.com

#

echo "############################################"

echo "############################################"

echo "##mkrootfs.sc created by do2jiang,2008,10 ##"

echo "##Email:do2jiang@gmai.com               ##"

echo "##http://blog.yesky.com/blog/langboy    ##"

echo "##                      ##"

echo "############################################"

echo "############################################"

 

 

################################################

# predefine of this script

 

# define rootfs path

ROOTFS=/fsroot2

 

# define lib path of CROSS-COMPILER

# this is "/usr/local/arm/2.95.3/arm-linux/lib"

CROSS_COMPILER_LIB=/usr/local/arm/2.95.3/arm-linux/lib

 

# define busybox source path

# this is "/usr/local/arm/busybox-1.00-pre10/arm_install"

BUSYBOX_ARMINSTALL=/usr/local/arm/busybox-1.00-pre10/arm_install

 

# define image path and image name

ROOTIMAGE=/mnt/fsroot2

IMAGENAME=fsroot2.img

 

# define download path

DOWNLOADPATH=/work/at9200/share

 

###############################################

# reset dir

cd    /

# create $ROOTFS structure

mkdir $ROOTFS

cd    $ROOTFS

# create dir

mkdir bin dev etc lib proc sbin tmp usr var lost+found

chmod 1777 tmp

mkdir usr/bin usr/lib usr/sbin

mkdir var/lib var/lock var/log var/run var/tmp

chmod 1777 var/tmp

echo "create $ROOTFS structure success!"

################################################

# copy lib file for rootfs from environment of CROSS-COMPILER

# this is "/usr/local/arm/2.95.3/arm-linux/lib"

cd $CROSS_COMPILER_LIB

 

for file in libc libcrypt libdl libm libpthread libresolv libutil;do cp $file-*.so  $ROOTFS/lib;cp -d $file.so.[*0-9]  $ROOTFS/lib;done

 

cp -d ld*.so* $ROOTFS/lib

echo "copy $ROOTFS/lib success!"

################################################

 

# make node file in dev dir

cd $ROOTFS/dev

 

mknod console c 5 1

mknod full c 1 7

mknod kmem c 1 2

mknod mem c 1 1

mknod null c 1 3

mknod port c 1 4

mknod random c 1 8

mknod urandom c 1 9

mknod zero c 1 5

 

for i in `seq 0 7`;do mknod loop$i b 7 $i;done

for i in `seq 0 9`; do mknod ram$i b 1 $i;done

ln -s ram1 ram

mknod tty c 5 0

for i in `seq 0 9`; do mknod tty$i c 4 $i;done

for i in `seq 0 9`; do mknod vcs$i b 7 $i;done

ln -s vcs0 vcs

for i in `seq 0 9`; do mknod vcsa$i b 7 $i;done                                      

ln -s vcsa0 vcsa

echo "make $ROOTFS/dev node success!"

###################################################

 

# create linuxrc file

LINUXRC=linuxrc2

 

cd $ROOTFS/

touch $LINUXRC

chmod 775 $LINUXRC<,o:p>

echo "#\!/bin/sh" >> $LINUXRC

echo "# " >> $LINUXRC

echo "# create by do2jiang , 2008.10"  >> $LINUXRC

echo "# do2jiang@gmail.com" >> $LINUXRC

echo "#" >> $LINUXRC

echo "echo "Hello linux\! Helo World\!"" >> $LINUXRC

echo "exec /sbin/init" >> $LINUXRC

echo "create $ROOTFS/$LINUXRC success!"

 

###################################################

# copy file in dir of  bin/ and sbin/

cd $ROOTFS/

cp -a $BUSYBOX_ARMINSTALL/* $ROOTFS/

echo "copy busybox applet success!"

 

###################################################

# copy system config file to $ROOTFS/etc dir

# etc dir is in $BUSYBOX_INSTALL/etc,haved been copied.

echo "copy system etc file success!"

 

###################################################

# make img file

cd /

mkdir $ROOTIMAGE

dd if=/dev/zero of=$IMAGENAME bs=1k count=9216

mke2fs -F -v -m0 $IMAGENAME

mount -o loop $IMAGENAME $ROOTIMAGE

 

#remove symble information

#arm-linux-strip $ROOTFS/lib/*

 

cp -a  $ROOTFS/* $ROOTIMAGE/

umount $ROOTIMAGE

gzip -9 $IMAGENAME

echo "create $IMAGENAME file success!"

 

#copy image file to DOWNLOAD PATH

cd /

cp $IMAGENAME.gz $DOWNLOADPATH

echo "copy file to $DOWNLOADPATH"

echo "ALL SET!"

####################################################

# add other!
阅读(1116) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~