LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1915|回复: 0

使用busybox做 cpio格式的initrd时需要解决的几个问题

[复制链接]
发表于 2009-7-5 13:47:49 | 显示全部楼层 |阅读模式
1、busybox切换根文件系统时的命令switch_root要求只能由PID=1的init进程调用,但是我们一般会把这条命令写在etc/init.d/rcS里面。这时调用这条命令的进程是busybox init,PID不等于1.
查看busybox源码,在 util-linux/switch_root.c 中的 switch_root_main函数有这么几行代码需要修改一下。

        // Additional sanity checks: we're about to rm -rf /,  so be REALLY SURE
        // we mean it.  (I could make this a CONFIG option, but I would get email
        // from all the people who WILL eat their filesystems.)
        if (lstat("/init", &st1) /* || !S_ISREG(st1.st_mode)*/ || statfs("/", &stfs)
         || (((unsigned)stfs.f_type != RAMFS_MAGIC) && ((unsigned)stfs.f_type != TMPFS_MAGIC))
/*       || (getpid() != 1)*/
        ) {
                bb_error_msg_and_die("not rootfs");
        }

把PID得判断和是否常规文件的判断注释掉。重新编译busybox就OK了!

  
2、修改rcS脚本:
#! /bin/sh

#/bin/mount -a
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys
mdev -s

modprobe BusLogic      #安装硬盘驱动

/bin/mount -t ext2 /dev/sdb /mnt

exec switch_root /mnt /linuxrc
这里新根文件系统是busybox做的,注意不能启动新根文件系统的init,否则会出问题。

3、制作initrd的根文件系统根目录下必须有init, busybox make install后在根目录下会有一个指向busybox的软链接,名字为linuxrc, 我们把它改名为init即可。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表