|
楼主 |
发表于 2004-12-10 15:50:57
|
显示全部楼层
我改变了一下根文件系统的创建方式,不直接去写/dev/ram,而是把/dev/ram先mount上来,再在里面创建根文件系统所需的基本文件.
[code:1]
static void __init create_my_rootfs(void)
{
int busybox_fd;
int inittab_fd;
int passwd_fd;
int group_fd;
int rcS_fd;
int test_fd;
int i;
char *busybox_cmd[]={"/bin/sh","/bin/login","/bin/ls","/sbin/init","/sbin/getty",NULL};
int ret;
ret=sys_mknod("/dev/ram", S_IFBLK|0755, MKDEV(RAMDISK_MAJOR, 0));
ret=sys_mkdir("/myrootfs",0755);
sys_chdir("/myrootfs");
ret=sys_mount("/dev/ram",".","ramfs",0,NULL);
sys_umount("/dev", 0);
sys_mount(".", "/", NULL, MS_MOVE, NULL);
sys_chroot(".");
sys_mkdir("/dev",0755);
sys_mkdir("/sbin",0755);
sys_mkdir("/etc",0755);
sys_mkdir("/etc/init.d",0755);
sys_mkdir("/proc",0755);
sys_mkdir("/tmp",0755);
sys_mkdir("/var",0755);
sys_mkdir("/root",0755);
sys_mknod("/dev/console", S_IFCHR|0600, MKDEV(5, 1));
sys_mknod("/dev/ttyS0", S_IFCHR|0600, MKDEV(4, 64));
test_fd=open("/etc/test", O_CREAT | O_RDWR ,S_IRWXU);
inittab_fd=open("/etc/inittab", O_CREAT | O_RDWR ,S_IRWXU);
rcS_fd=open("/etc/init.d/rcS", O_CREAT | O_RDWR ,S_IRWXU);
passwd_fd=open("/etc/passwd", O_CREAT | O_RDWR ,S_IRWXU);
group_fd=open("/etc/group", O_CREAT | O_RDWR ,S_IRWXU);
if(!inittab_fd)
{
printk("### cannot open /etc/inittab\n");
}
else
{
write(inittab_fd,"::sysinit:/etc/init.d/rcS\nttyS0::respawn:-/sbin/getty -L ttyS0 9600 vt100\n",
strlen("::sysinit:/etc/init.d/rcS\nttyS0::respawn:-/sbin/getty -L ttyS0 9600 vt100\n"));
close(inittab_fd);
}
if(!rcS_fd)
{
printk("### cannot open /etc/init.d/rcS\n");
}
else
{
write(rcS_fd,"#! /bin/sh\nPATH=/bin:/sbin\n",strlen("#! /bin/sh\nPATH=/bin:/sbin\n"));
close(rcS_fd);
}
if(!passwd_fd)
{
printk("### cannot open /etc/passwd\n");
}
else
{
write(passwd_fd,"root:.GNRdJai/a8pc:0:0::/root:/bin/sh\n",
strlen("root:.GNRdJai/a8pc:0:0::/root:/bin/sh\n"));
close(passwd_fd);
}
if(!group_fd)
{
printk("### cannot open /etc/group\n");
}
else
{
write(group_fd,"root:x:0:root\n",strlen("root:x:0:root\n"));
close(group_fd);
}
i=0;
while(busybox_cmd[i] != NULL)
{
busybox_fd=open(busybox_cmd[i], O_CREAT | O_RDWR ,S_IRWXU);
if(!busybox_fd)
{
printk("### cannot create %s\n",busybox_cmd[i]);
}
else
{
ret=write(busybox_fd,busybox_data,sizeof(busybox_data));
close(busybox_fd);
printk("### create %s successfully\n",busybox_cmd[i]);
}
i++;
}
}
[/code:1]
我用这段代码来代替mount_root(),根文件系统能成功创建,init进程也起来了,但init执行getty时,getty老是执行不了/bin/login,说/bin/login不存在,我明明已经创建了这个程序.
本来我是想建立一个/bin/busybox,然后其他程序做个链接就行了,但我用sys_smblink却不能成功创建链接,不得已,我只好为每个busybox支持的命令都创建一个实体. |
|