构建根文件系统之构建根文件系统(二)

上篇中,已经制作了一个不能再小的根文件系统。本篇将继续完善根文件系统

在开发板上执行ps命令后,会出现如下内容:

ps
PID Uid VSZ Stat Command
ps: can't open '/proc': No such file or directory说不能打开/proc,没有这个文件或目录

进入linux中,

cd /work/nfs_root/first_fs

mkdir proc,生成proc目录,即使有了proc这个目录,还是不够的。需要挂接一个虚拟的文件系统

你可以实验一下,在单板上

mkdir  proc,然后再ps

ps
PID Uid VSZ Stat Command

在内核中,当前有哪些应用程序在运行,信息是如何收集的。内核提供了一个虚拟的文件系统。

mount  -t  proc  none  /proc,然后再ps看一下:

ps
PID Uid VSZ Stat Command
1 0 3092 S init
2 0 SW< [kthreadd]
3 0 SWN [ksoftirqd/0]
4 0 SW< [watchdog/0]
5 0 SW< [events/0]
6 0 SW< [khelper]
55 0 SW< [kblockd/0]
56 0 SW< [ksuspend_usbd]
59 0 SW< [khubd]
61 0 SW< [kseriod]
73 0 SW [pdflush]
74 0 SW [pdflush]
75 0 SW< [kswapd0]
76 0 SW< [aio/0]

710 0 SW< [mtdblockd]

745 0 SW< [kmmcd]
763 0 3096 S -sh
771 0 3096 R ps

cd /proc/
# ls
1 745 diskstats locks sys
2 75 driver meminfo sysrq-trigger
3 76 execdomains misc sysvipc
4 763 fb modules timer_list
5 772 filesystems mounts tty
55 asound fs mtd uptime
56 buddyinfo interrupts net version
59 bus iomem partitions vmstat
6 cmdline ioports scsi yaffs
61 cpu irq self zoneinfo
710 cpuinfo kallsyms slabinfo
73 crypto kmsg stat
74 devices loadavg swaps

cd 1  1为进程号
# ls -l fd
lrwx------ 1 0 0 64 Jan 1 00:20 0 -> /dev/console
lrwx------ 1 0 0 64 Jan 1 00:20 1 -> /dev/console
lrwx------ 1 0 0 64 Jan 1 00:20 2 -> /dev/console

如果不想手工挂载的话,就需要加上一个配置文件,到linux服务器上。

还是进入first_fs文件中,打开etc/inittab加入这样一句:

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

然后再创建mkdir etc/init.d

cd etc/init.d

vim rcS

 加入mount -t proc none /proc

然后给该文件加上一个可执行的属性

chmod +x etc/init.d/rcS

mkyaffs2image  first_fs  first_fs1.yaffs2

然后将first_fs1.yaffs2烧写到开发板,会出现如下所示:

VFS: Mounted root (yaffs filesystem).
Freeing init memory: 140K
init started: BusyBox v1.7.0 (2017-06-28 10:14:47 CST)
starting pid 764, tty '': '/etc/init.d/rcS'

Please press Enter to activate this console.
starting pid 766, tty '/dev/console': 'bin/sh'

此时再执行,ps

ps
PID Uid VSZ Stat Command
1 0 3092 S init
2 0 SW< [kthreadd]
3 0 SWN [ksoftirqd/0]
4 0 SW< [watchdog/0]
5 0 SW< [events/0]
6 0 SW< [khelper]
55 0 SW< [kblockd/0]
56 0 SW< [ksuspend_usbd]
59 0 SW< [khubd]
61 0 SW< [kseriod]
73 0 SW [pdflush]
74 0 SW [pdflush]
75 0 SW< [kswapd0]
76 0 SW< [aio/0]
710 0 SW< [mtdblockd]
745 0 SW< [kmmcd]
766 0 3096 S -sh
768 0 3096 R ps

 

除了mount  -t 外,还有另一种办法:mount  -a

mount  -a 去读一个 etc/fstab,根据这个配置文件里面的内容挂载根文件系统。

将etc/init.d/rcS中的内容改为mount  -a  ,该命令后将挂接proc、tmpfs文件系统:

然后再去填充 /etc/fstab中的内容,格式如下:

#device   mount-point    type    options    dump   fsck    order

proc         /proc              proc      defaults    0        0

tmpfs       /tmp                tmpfs     defaults    0       0

然后重新烧写,生成first_fs2.yaffs2,烧写到开发板,同样达到了效果。

 

继续完善:

看一下开发板中,dev目录下的东西:

ls /dev

console  null

dev目录对应那些驱动,有很多很多,每个都这样做的话,会非常的麻烦。有一种方法:udev机制,解决了这个问题。方便你我他。

udev自动创建dev目录下的设备节点。在busybox中,有一个udev的简化版本。是mdev

(1)打开etc/fstab,,加入如下的内容:

sysfs     /sys      sysfs       defaults    0    0

tmpfs    /dev      tmpfs       defaults    0    0

(2)在etc/init.d/rcS中加入这几行:

mkdir   /dev/pts

mount  -t   devpts   devpts   /dev/pts

echo /sbin/mdev  > /proc/sys/kernel/hotplug

mdev -s

然后再将first_fs3.yaffs2烧到开发板,再看一下:

ls -l /dev,会列出很多很多的设备,这里只列出一部分:

crw-rw---- 1 0 0 2, 243 Jan 1 00:00 ptye3
crw-rw---- 1 0 0 2, 244 Jan 1 00:00 ptye4
crw-rw---- 1 0 0 2, 245 Jan 1 00:00 ptye5
crw-rw---- 1 0 0 2, 246 Jan 1 00:00 ptye6
crw-rw---- 1 0 0 2, 247 Jan 1 00:00 ptye7
crw-rw---- 1 0 0 2, 248 Jan 1 00:00 ptye8
crw-rw---- 1 0 0 2, 249 Jan 1 00:00 ptye9
crw-rw---- 1 0 0 2, 250 Jan 1 00:00 ptyea
crw-rw---- 1 0 0 2, 251 Jan 1 00:00 ptyeb
crw-rw---- 1 0 0 2, 252 Jan 1 00:00 ptyec
crw-rw---- 1 0 0 2, 253 Jan 1 00:00 ptyed
crw-rw---- 1 0 0 2, 254 Jan 1 00:00 ptyee
crw-rw---- 1 0 0 2, 255 Jan 1 00:00 ptyef
crw-rw---- 1 0 0 2, 0 Jan 1 00:00 ptyp0
crw-rw---- 1 0 0 2, 1 Jan 1 00:00 ptyp1
crw-rw---- 1 0 0 2, 2 Jan 1 00:00 ptyp2
crw-rw---- 1 0 0 2, 3 Jan 1 00:00 ptyp3
crw-rw---- 1 0 0 2, 4 Jan 1 00:00 ptyp4
crw-rw---- 1 0 0 2, 5 Jan 1 00:00 ptyp5
crw-rw---- 1 0 0 2, 6 Jan 1 00:00 ptyp6
crw-rw---- 1 0 0 2, 7 Jan 1 00:00 ptyp7
crw-rw---- 1 0 0 2, 8 Jan 1 00:00 ptyp8
crw-rw---- 1 0 0 2, 9 Jan 1 00:00 ptyp9
crw-rw---- 1 0 0 2, 10 Jan 1 00:00 ptypa
crw-rw---- 1 0 0 2, 11 Jan 1 00:00 ptypb
crw-rw---- 1 0 0 2, 12 Jan 1 00:00 ptypc

这样最小的根文件系统就比较完善了。

如果想使用其它格式的根文件系统,比如说jffs2呢?一般jffs2用在nor  flash上,当然用在nand  flash上也是可以的。

进入/work/tools/GUI/xwindow/x/deps

tar xzf zlib-1.2.3.tar.gz

cd zlib-1.2.3

./config --shared --prefix=/usr  说明在/usr目录下安装

make

make install

然后编译mkfs.jffs2

cd /work/tools

tar xjf mtd-utils-05.07.23.tar.bz2

cd mtd-utils-05.07.23/util

make

make install

 

制作/烧写jffs2映像文件

cd /work/nfs_root

mkfs.jffs2  -n  -s 2048 -e 128KiB -d first_fs  -o first_fs.jffs2

-s表示一页的大小,我的是2048

-e表示一个擦除块的大小

 

posted @ 2017-06-28 16:08  一代枭雄  阅读(429)  评论(0编辑  收藏  举报