制作initrd

首先,制作Initrd,需要了解,inidrd是什么,它由什么构成的。
然后,我们会发现,在嵌入式的Initrd中 busybox是一个非常常用的工具,可是,到底busybox在制作initrd中扮演什么样的角色呢?
其实,initrd只是引入了一些应用程序而已,只是,这些应用程序做的很好,体积很小。当然,因为它是缩水版的,于是,一些功能就没有啦,比如 ls -al ,就只相当于ls.
因此,不要指望busybox能够做所有的事情。
我们还需要做一些必要的目录,比如 etc lib 等。
下面是我做Initrd的一些步骤。其中,参考了cublog上的一篇日志。
http://blog.chinaunix.net/u2/70445/showart_1163143.html
转载,请注明。
首先下载busybox1.9.1版本,然后解压缩,相信大家都会。然后step by step
1、更改busybox1.9.1的Makefile
ARCH ?=arm
CROSS_COMPILE?= 自己的交叉编译环境的位置我的是:/opt/crosstool/gcc-4.1.0-glibc-2.3.2/arm-linux/bin/arm-linux-
2、make menuconfig
Busybox Setting----->
build option-->
[ ] Build BusyBox as a static binary (no shared libs)

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)

installation option-->

Don't use /usr
Applets links (as soft-links) --->
(./_install) BusyBox installation prefix

Busybox Library Tuning --->

MD5: Trade Bytes for Speed

Faster /proc scanning code (+100 bytes)

Support for /etc/networks


Support for /etc/networks

Additional editing keys

vi-style line editing commands

History saving

Tab completion

Username completion

Fancy shell prompts

Linux Module Utilities --->

Support version 2.6.x Linux kernels


insmod

Enable load map (-m) option

Symbols in load map

rmmod

lsmod

lsmod pretty output for 2.6.x Linux kernels

modprobe
[ ] Multiple options parsing
[ ] Fancy alias parsing
--- Options common to multiple modutils
[ ] Support tainted module checking with new kernels
[ ] Support version 2.2.x to 2.4.x Linux kernels


Support version 2.6.x Linux kernels

其他的用默认值

3、make install 开始安装
在busybox的根目录下生成_install文件夹,里面的东西有3项:bin sbin linuxrc

4、修改安装Busybox后的busybox文件属性,具体原因,随后再续。
chmod 4755 ./_install/bin/busybox
5、在自己的home目录中,建立rootfs目录
将_install的内容拷贝到rootfs目录中

6、在rootfs目录下,建立空目录:
dev home proc tmp var
boot etc lib mnt root sys usr
7、此时 rootfs目录下有如下内容:
bin dev home linuxrc proc sbin tmp var
boot etc lib mnt root sys usr
8、
以root身份建立节点文件/dev/console, /dev/null
mknod -m 600 dev/console c 5 1
mknod -m 666 dev/null c 1 3

9、进入etc目录,建立profile文件,内容如下:
#!/bin/sh
#/etc/profile:system-wide .profile file for the Bourne shells

echo
echo -n "Processing /etc/profile......"

# Set search library path
export LD_LIBRARY_PATH=/lib:/usr/lib

# set user path
export PATH=/bin:/sbin:/usr/bin:/usr/sbin

#Set PS1
USER = "`id -un`"
LOGNAME=$USER
PS1='[\u@\h\W]\$'
PATH=$PATH

echo "Done!"
10、
在etc目录下建立init.d目录,然后在init.d目录下建立rcS文件
init.d/rcS内容:
#!/bin/sh

# set hostname, needed host file in /etc directory
#./etc/host
hostname `cat /etc/host`

# mount all filesystem defined in "fstab"
echo "#mount all......."
/bin/mount -a

#+/bin/chmod 0666 /dev/null

echo "# starting mdev...."
/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

/usr/etc/init

echo "******************************************"
echo " "
echo " "
echo " "
echo "******************************************"

11、在etc目录下建立fstab文件
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
none /var ramfs defaults 0 0
mdev /dev ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
12、在etc目录下建立inittab文件
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh

tty2::askfirst:-/bin/sh

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

::shutdown:/bin umount -a -r
::shutdown:/sbin/swapoff -a
13、在etc目录下建立空文件
mdev.conf
14、
复制主机/etc/下面的文件passwd, group, shadow文件到/etc
[root@centos etc]# cp /etc/group .
[root@centos etc]# cp /etc/passwd .
[root@centos etc]# cp /etc/shadow .
15、
因为是编译的时候使用的是动态链接。所以先看看~/busybox/_install/bin/busybox使用了哪些 lib,然后从glibc复制相应的lib到~/fsroot/lib中。
[root@centos bin]# /usr/local/arm/3.4.1/arm-linux-gnu-readelf -d busybox
Dynamic section at offset 0xb8014 contains 22 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library:[libcrypt.so.1]
0x00000001 (NEEDED) Shared library: [libm.so.6]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0xc04c
0x0000000d (FINI) 0xa26f0
0x00000004 (HASH) 0x80e8
0x00000005 (STRTAB) 0xa384
0x00000006 (SYMTAB) 0x8b24
……
……
……
复制lib 文件到lib目录下:
[root@centos lib]cp /usr/local/arm/3.4.1/arm-linux/lib/ld* .
[root@centos lib]cp /usr/local/arm/3.4.1/arm-linux/lib/libc-2.3.2.so .
[root@centos lib]cp /usr/local/arm/3.4.1/arm-linux/lib/libc.so.6 .
[root@centos lib]cp /usr/local/arm/3.4.1/arm-linux/lib/libm * .
[root@centos lib]cp /usr/local/arm/3.4.1/arm-linux/lib/libcrypt* .
16、进入busybox根目录下,进入usr目录下,建立etc目录
在该etc目录下建立init文件
#!/bin/sh
ifconfig eth0 192.168.1.111 up
ifconfig lo 127.0.0.1

17、 mkcramfs fsroot fs_2.6.26_busybox.cramfs
18、利用之前编译好的zImage引导操作系统

讨论贴:
http://linux.chinaunix.net/bbs/thread-1162326-1-1.html

评论

此博客中的热门博文

Linux/ARM Page Table Entry 属性设置分析

提交了30次才AC ---【附】POJ 2488解题报告

笔记