linux-2.6.18以上版本完全抛弃了 devfs,使用 udev. udev可以在 http://www.kernel.org/pub/linux/utils/kernel/hotiflags目录下找到,不过 busybox高版本提供了 udev的简化版 mdev.
作 linux kernel 高版本能引导的文件系统 rootfs 步骤:
1. 创建必须的文件夹及设备文件
# mkdir rootfs
# cd rootfs
# mkdir bin dev etc lib mnt proc sbin sys root
# mkdir etc/var etc/tmp etc/sysconfig
# ln -s etc/var var
# ln -s etc/tmp tmp
2。创建设备文件系统
新版本的udev是一个基于用户空间的设备管理系统。在内核启动时并不能
自动创建设备节点,固需手动创建console和null两个启动过程必须的设
备节点。我们将采用busybox中内置的mdev,一个简化的udev版本.
# mknod -m 660 dev/console c 5 1
# mknod -m 660 dev/null c 1 3
3. 建立动态运行库
# cp -rfd 交叉编译器位置/arm-linux/lib/* rootfs/lib/
# rm -rf rootfs/lib/*.a
# arm-linux-strip rootfs/lib/*
4. 交叉编译busybox
解压后修改Makefile,指明交叉编译器:
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
执行 make menuconfig
选择系统需要用到的命令或工具。
值得注意的是 shell 的选择,在 Choose your default shell (none) 这一项回车后选择ash
Busybox settings --->
Build option --->
[*] Build BusyBox as a static binary (no shared libs)
Linux System Utilities --->
[*] mdev
[*] Support /etc/mdev.conf
[ ] Support command execution at device addition/removal
必须选择 mdev 选项, 否则不能启用udev。
执行 make install进行编译,编译完后,会出现_install目录,包含bin、sbin、usr三个目录和一个linuxrc文件。
linuxrc是linux启动后第一执行的文件(由u-boot传给linux的启动参数决定,在kernel的boot option 的目录),其作用是执行相应的初始化工作。但u-boot编译生成的仅是一个指向/bin/busybox的链接文件。由于我们需要作一些初始化工作,如启动web服务器,加载特定驱动程序等,我们将自行编写linuxrc这个文件。bin、sbin、usr这三个目录里除了bin/busybox一个文件外,其余都是指向busybox的链接文件。我们将bin、sbin、usr这三个目录和linuxrc这个链接文件拷贝到rootfs的目录下,基本的文件系统制作完成
问题1, 使用jffs2文件系统:
JFFS2 error: (1) jffs2_build_inode_pass1: child dir "fonts" (ino #13) of dir ino #4 appears to be a hard link
VFS: Mounted root (jffs2 filesystem).
Freeing unused kernel memory: 304k freed
Warning: unable to open an initial console.
Failed to execute /linuxrc. Attempting defaults...
Kernel panic - not syncing: No init found. Try passing init= option to kernel.
原因: flash没有erase彻底.
问题2, 使用cramfs时出错:
VFS: Mounted root (cramfs filesystem) readonly.
Freeing unused kernel memory: 304k freed
Error -3 while decompressing!
804878c4(1884)->81200000(16384)
Failed to execute /linuxrc. Attempting defaults...
Kernel panic - not syncing: No init found. Try passing init= option to kernel.
原因: 没有仔细看 mkfs.cramfs 的手册, 需要指定-b参数, 大小与PAGE_SIZE一样 (查看.config文件 CONFIG_PAGE_SIZE_16KB=y).
问题3 :
Kernel panic - not syncing: Attempted to kill init!
原因: 应该是/etc/fstab 之类的文件没有,重做文件系统后OK
问题4, 一直提示找不到/dev/tty2-4, 按下[Enter]后死机:
VFS: Mounted root (jffs2 filesystem).
Freeing unused kernel memory: 304k freed
init started: BusyBox v1.12.1 (2008-10-13 13:37:42 CST)
starting pid 696, tty '': '/etc/init.d/rcS'
cannot run '/etc/init.d/rcS': No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
process '-/bin/sh' (pid 698) exited. Scheduling for restart.
process '-/bin/sh' (pid 699) exited. Scheduling for restart.
本文介绍如何为Linux Kernel 2.6.18及以上版本构建根文件系统(rootfs),包括使用udev和mdev创建必要的设备文件,配置并交叉编译BusyBox,以及解决常见错误的方法。

4091

被折叠的 条评论
为什么被折叠?



