原创
arm-linux学习之busybox文件系统(一)
移植linux到arm平台,完成bootloader和kernel之后就要制作自己的文件系统。这个东西搞的大爷很惨,上网查了很多资料,最初是从cramfs文件系统开始,然后ramdisk的ext2文件系统,最后才是jffs2文件系统。开始是找不到系统,后来是can't access tty,joy control turn off,后来是不能运行自己的程序。不知道怎么淡出就没有作笔记的习惯,现在从新作同样的事情的时候却又不出现这样的问题了¥#%@#……%¥……%
(1)下载并且配置busybox,偶使用的版本是busybox-1.13.0.tar.gz,解压缩,
[root@localhost busybox]# cd busybox-1.13.0
[root@localhost busybox-1.13.0]# make menuconfig
[root@localhost busybox-1.13.0]# make
[root@localhost busybox-1.13.0]# make install PREFIX=_install
其中配置时:
Busybox Settings --->
Build Options --->
[ ] Build BusyBox as a static binary (no shared libs) //采用静态编译的方式,不需要lib的支持,这种办法比较简单,但是不能运行自己的程序,所以选择下面的 Build shared libbusybox 方式,但是需要手动把运行程序以来的lib文件copy到/lib中。
[ ] Build BusyBox as a position independent executable
[ ] Force NOMMU build
Build shared libbusybox
[ ] Produce a binary for each applet, linked against libbusybox
[ ] Produce additional busybox binary linked against libbusybox
[ ] Build with Large File Support (for accessing files > 2 GB)
(arm-9tdmi-linux-gnu-) Cross Compiler prefix //交叉编译
其他各项的配置省略,把.config文件放在后面。使用命令执行make install PREFIX=_install执行安装,目标在_install目录之下。安装完成之后会得到以下几个目录和一个文件
[root@localhost _install]# ls
bin linuxrc sbin usr
[root@localhost _install]# ls -l
总计 28
drwxr-xr-x 2 root root 4096 11-30 04:22 bin
lrwxrwxrwx 1 root root 11 11-30 04:22 linuxrc -> bin/busybox
drwxr-xr-x 2 root root 4096 11-30 04:22 sbin
drwxr-xr-x 4 root root 4096 11-30 04:22 usr
其中有个linuxrc文件,这就是默认情况下的脚本文件,一般需要自己编写这个文件。其实bosybox编译的结构就是一个二进制二文件busybosy,其他命令像ls,cd等等所有都是连接到busybox这个文件的。这一点比较#@#¥@#%。
(二)制作跟文件系统
1、顶层文件系统
在/home/arm/建立一个root_dir的目录,然后在root_dir下面建立以下目录
[root@localhost root_dir]# ls
bin etc lib mnt root sys usr
dev home lib64 proc sbin tmp var
再建立一个linuxrc的文件,将其属性改成可执行的脚本。
[root@localhost root_dir]# ls
bin etc lib linuxrc mnt root sys usr
dev home lib64 proc sbin tmp var
然后把刚才编译的busybox的的_install的bin sbin usr这三个目录全部copy到/home/arm/root_dir
下。
查看一下
[root@localhost root_dir]# cd bin
[root@localhost bin]# ls
addgroup cp egrep login mountpoint rm umount
adduser cpio fgrep ls mt rmdir uncompress
ash date grep lsattr mv run-parts vi
busybox delgroup gunzip makemime ping sh zcat
cat deluser gzip mkdir pipe_progress su
chattr dmesg ip mknod ps tar
chmod dumpkmap kill mktemp pwd tinylogin
chown echo ln mount reformime touch
[root@localhost bin]# ls -l
总计 1104
lrwxrwxrwx 1 root root 9 11-15 00:16 addgroup -> tinylogin
lrwxrwxrwx 1 root root 9 11-15 00:16 adduser -> tinylogin
lrwxrwxrwx 1 root root 7 11-30 04:24 ash -> busybox
-rwxr-xr-x 1 root root 431172 11-30 04:22 busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 cat -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 chattr -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 chmod -> busybox
lrwxrwxrwx 1 root root 7 11-18 03:18 chown -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 cp -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 cpio -> busybox
lrwxrwxrwx 1 root root 7 11-18 03:18 date -> busybox
lrwxrwxrwx 1 root root 9 11-15 00:16 delgroup -> tinylogin
lrwxrwxrwx 1 root root 9 11-15 00:16 deluser -> tinylogin
lrwxrwxrwx 1 root root 7 11-30 04:24 dmesg -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 dumpkmap -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 echo -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 egrep -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 fgrep -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 grep -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 gunzip -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 gzip -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 ip -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 kill -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 ln -> busybox
lrwxrwxrwx 1 root root 9 11-15 00:16 login -> tinylogin
lrwxrwxrwx 1 root root 7 11-30 04:24 ls -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 lsattr -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 makemime -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mkdir -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mknod -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mktemp -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mount -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mountpoint -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mt -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 mv -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 ping -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 pipe_progress -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 ps -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 pwd -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 reformime -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 rm -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 rmdir -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 run-parts -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 sh -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 su -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 tar -> busybox
-rwsr-xr-x 1 root root 473256 11-15 00:16 tinylogin
lrwxrwxrwx 1 root root 7 11-18 03:18 touch -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 umount -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 uncompress -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 vi -> busybox
lrwxrwxrwx 1 root root 7 11-30 04:24 zcat -> busybox
[root@localhost bin]#
2、设备节点
在dev目录下创建三个节点
[root@localhost dev]# ls -al
总计 28
crw-r--r-- 1 root root 5, 1 11-28 23:28 console
crw-r--r-- 1 root root 1, 3 11-14 23:57 null
crw-r--r-- 1 root root 1, 5 11-14 23:57 zero
当然这几个节点远远不够,需要的时候在给据major 和minor补充
3、inittab文件
inittab是init程序的配置文件,busybox目录下有个exmples目录(/home/arm/busybox/busybox-1.13.0/examples)该目录下有个示例inittab
/home/arm/busybox/busybox-1.13.0/examples中inittab文件第38行到46行
# Note: BusyBox init works just fine without an inittab. If no inittab is
# found, it has the following default behavior:
# ::sysinit:/etc/init.d/rcS
# ::askfirst:/bin/sh
# ::ctrlaltdel:/sbin/reboot
# ::shutdown:/sbin/swapoff -a
# ::shutdown:/bin/umount -a -r
# ::restart:/sbin/init
#
# if it detects that /dev/console is _not_ a serial console, it will
# also run:
# tty2::askfirst:/bin/sh
# tty3::askfirst:/bin/sh
# tty4::askfirst:/bin/sh
如果出现can't access tty2,joy control turn off,等等,症结可能在这里。
将/home/arm/busybox/busybox-1.13.0/examples/inittab 文件copy到/home/arm/root_dir/etc/目录下,并根据自己的要求修改就行了。(待续)
文章评论(0条评论)
登录后参与讨论