下载busybox 1.00 http://busybox.net/downloads/busybox-1.00.tar.bz2
# tar jxvf busybox-1.00.tar.bz2
# cd busybox-1.00
# make defconfig
# make menuconfig 配置
# make
# make install
需要cp到ramdisk的文件在_install目录中
下面主要分析一下内核到busybox的启动流程
在kernel/init/main.c的init函数中有代码
if (execute_command)
execve(execute_command,argv_init,envp_init);
execve("/sbin/init",argv_init,envp_init);
一般启动命令行会给出 init=/linuxrc 这个参数,于是就有了
execute_command = "/linuxrc"
busybox中_install目录下的 linuxrc 是busybox的一个软链接
而在我的ramdisk中已经被替换成一个shell脚本,其中的代码是
#!/bin/sh
exec /sbin/init
所以其实这个linuxrc基本没什么用处,我就可以把
if (execute_command) execve(execute_command,argv_init,envp_init);
这句代码注释掉,于是内核就直接运行/sbin/init了
/sbin/init也是busybox的软链接,所以接着下来就要看busybox的源代码了
入口函数main在busybox-1.00/applets/busybox.c中
int main(int argc, char **argv)
{
const char *s;
bb_applet_name = argv[0];
if (bb_applet_name[0] == '-') bb_applet_name++;
for (s = bb_applet_name; *s != '/0';)
{
if (*s++ == '/') bb_applet_name = s;
}
#ifdef CONFIG_LOCALE_SUPPORT
#ifdef CONFIG_INIT
if(getpid()!=1) /* Do not set locale for `init' */
#endif
{ setlocale(LC_ALL, ""); }
#endif
run_applet_by_name(bb_applet_name, argc, argv);
bb_error_