问题:
1.目前busybox和bootstrap两种方案制作文件系统,哪种开发周期更短,更加简单?
2.如果需要在文件系统中添加某个package,要怎么做,如vim/udhcpd等?
转自:http://blog.csdn.net/happy_stars_2016/article/details/52620577
定制根文件系统的方法很多,最常用的是使用BusyBox来构建。它能使用户迅速方便地建立一套相对完整、功能丰富的文件系统,其中包括大量常用的应用程序。它集成压缩了Linux的许多工具和命令。下面详细介绍有关BusyBox定制根文件系统。
一、系统环境:
1、操作系统:Ubuntu12.04
2、交叉编译工具:arm-linux-gcc4.4.3
3、busybox源码包:busybox-1.25.0.tar.bz2
二、制作rootfs
- 建立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
- 解压源码包:
#tar -jxvf busybox-1.25.0.tar.bz2
- 修改Makefile配置
进入busybox-1.25.0目录,修改Makefile文件如下:
ARCH ?= arm CROSS_COMPILE ?= /usr/local/arm/4.4.3/bin/arm-linux- (与你自己主机的arm-linux-gcc安装目录一样)
- 编译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
保存并退出
- 编译安装
#make
#make install
- 把busybox源码目录下的etc的内容拷贝到rootfs目录下的etc下
# cd /home/zxx/rootfs/etc # cp -a /home/zxx/Downloads/busybox-1.25.0/examples/bootfloppy/etc/* ./
- 从本机拷贝passwd、shadow、group文件
# cp /etc/passwd . # cp /etc/shadow . # cp /etc/group .
修改passwd文件,把第一行和最后一行的bash修改成ash。
- 修改初始化文件inittab和fstab
# 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
- rootfs下lib的制作
将交叉编译环境下lib库拷贝到/rootfs/lib
#cd /home/zxx/rootfs/lib #cp /usr/local/arm/4.4.3/arm-none-linux-gnueabi/sys-root/lib./
三、编译错误解决参考
- make出现如下错误:
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拷贝到busybox的include文件中。
#gedit miscutils/nandwrite.c
修改头文件如下:
#include "libbb.h" #include "mtd-abi.h" #include <mtd/mtd-user.h>
编译可以通过。
- 继续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拷贝到busybox的include文件中linux下。
#gedit util-linux/blkdiscard.c
修改内容如下:
#include <linux/fs.h>
编译通过。
到这里rootfs基本上已经制作出来,有些内容需要的,可根据自己rootfs的需要进行自己增加。最后将rootfs目录制作成镜像后,就可以烧写到开发板上了。