BusyBox制作根文件系统(rootfs)

定制根文件系统的方法很多,最常用的是使用BusyBox来构建。它能使用户迅速方便地建立一套相对完整、功能丰富的文件系统,其中包括大量常用的应用程序。它集成压缩了Linux的许多工具和命令。下面详细介绍有关BusyBox定制根文件系统。

 

一、系统环境:

1、操作系统:Ubuntu12.04

2、交叉编译工具:arm-linux-gcc4.4.3

3busybox源码包:busybox-1.25.0.tar.bz2

 

二、制作rootfs

1、建立rootfs目录

本人在/home/zxx下建立rootfs目录

#mkdir rootfs

#cd rootfs

#mkdir root home bin sbin etc dev usr lib tmp mnt sys proc  //建立常用目录

#mkdir usr/lib usr/bin

#pwd

/home/zxx/rootfs

2、解压源码包:

#tar -jxvf busybox-1.25.0.tar.bz2

3、修改Makefile配置

进入busybox-1.25.0目录,修改Makefile文件如下:

ARCH ?= arm

CROSS_COMPILE ?= /usr/local/arm/4.4.3/bin/arm-linux- (与你自己主机的arm-linux-gcc安装目录一样)

4、编译BusyBox

 #make menuconfig

选择Busybox Settings--->Build Options--->,选择[*] Build Busybox as a static binary(no shared libs)

 

选择Busybox Settings ---> Installation Options --->BusyBox installation prefix(在里面输入BusyBox的安装目录,我是保存在/home/zxx/rootfs下)

 

 

Shells --->Choose your default shell (ash) --->  --- ash

保存并退出

5、编译安装

#make

#make install

6、把busybox源码目录下的etc的内容拷贝到rootfs目录下的etc

# cd /home/zxx/rootfs/etc

# cp -a /home/zxx/Downloads/busybox-1.25.0/examples/bootfloppy/etc/* ./

7、从本机拷贝passwdshadowgroup文件

# cp /etc/passwd .

# cp /etc/shadow .

# cp /etc/group .

修改passwd文件,把第一行和最后一行的bash修改成ash

9、修改初始化文件inittabfstab

# vim inittab

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

::respawn:-/bin/sh

::restart:/sbin/init

 

tty2::askfirst:-/bin/sh

::ctrlaltdel:/bin/umount -a -r

::shutdown:/bin/umount -a -r

::shutdown:/sbin/swapoff a

 

# vim fstab

proc /proc proc defaults 0 0

none /tmp ramfs defaults 0 0

mdev /dev ramfs defaults 0 0

sysfs /sys sysfs defaults 0 0

10、rootfslib的制作

将交叉编译环境下lib库拷贝到/rootfs/lib

#cd /home/zxx/rootfs/lib

#cp /usr/local/arm/4.4.3/arm-none-linux-gnueabi/sys-root/lib./

三、编译错误解决参考

1make出现如下错误:

miscutils/nandwrite.c: In function 'nandwrite_main':

miscutils/nandwrite.c:151: error: 'MTD_FILE_MODE_RAW' undeclared (first use in this?function)

miscutils/nandwrite.c:151: error: (Each undeclared identifier is reported only once

miscutils/nandwrite.c:151: error: for each function it appears in.)

scripts/Makefile.build:197: recipe for target 'miscutils/nandwrite.o' failed

make[1]: *** [miscutils/nandwrite.o] Error 1

Makefile:742: recipe for target 'miscutils' failed

make: *** [miscutils] Error 2

 

解决办法:

MTD_FILE_MODE_RAW/usr/include/mtd/mtd-abi.h中定义。将/usr/include/mtd/mtd-abi.h拷贝到busyboxinclude文件中。

#gedit miscutils/nandwrite.c 

修改头文件如下:

 #include "libbb.h"

#include "mtd-abi.h"

#include <mtd/mtd-user.h>

编译可以通过。

2、继续make,出现如下错误:

util-linux/blkdiscard.c: In function 'blkdiscard_main':

util-linux/blkdiscard.c:72: error: 'BLKSECDISCARD' undeclared (first use in this function)

util-linux/blkdiscard.c:72: error: (Each undeclared identifier is reported only once

util-linux/blkdiscard.c:72: error: for each function it appears in.)

scripts/Makefile.build:197: recipe for target 'util-linux/blkdiscard.o' failed

make[1]: *** [util-linux/blkdiscard.o] Error 1

Makefile:742: recipe for target 'util-linux' failed

make: *** [util-linux] Error 2

 

解决办法:

BLKSECDISCARD/usr/include/linux/fs.h中定义,方法如上所述,将/usr/include/linux/fs.h拷贝到busyboxinclude文件中linux下。

#gedit util-linux/blkdiscard.c

修改内容如下:

#include <linux/fs.h>

编译通过。

 

 

到这里rootfs基本上已经制作出来,有些内容需要的,可根据自己rootfs的需要进行自己增加。最后将rootfs目录制作成镜像后,就可以烧写到开发板上了。

 

 

 

 


  • 3
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值