|
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即可。 |
|