2 #include <linux/kernel.h>
4 #include <linux/minix_fs.h>
5 #include <linux/ext2_fs.h>
6 #include <linux/romfs_fs.h>
7 #include <linux/initrd.h>
11 unsigned int real_root_dev
; /* do_proc_dointvec cannot handle kdev_t */
12 static int __initdata old_fd
, root_fd
;
13 static int __initdata mount_initrd
= 1;
15 static int __init
no_initrd(char *str
)
21 __setup("noinitrd", no_initrd
);
23 static int __init
do_linuxrc(void * shell
)
25 static char *argv
[] = { "linuxrc", NULL
, };
26 extern char * envp_init
[];
28 close(old_fd
);close(root_fd
);
29 close(0);close(1);close(2);
31 (void) open("/dev/console",O_RDWR
,0);
34 return execve(shell
, argv
, envp_init
);
37 static void __init
handle_initrd(void)
42 real_root_dev
= ROOT_DEV
;
43 create_dev("/dev/root.old", Root_RAM0
, NULL
);
44 /* mount initrd on rootfs' /root */
45 mount_block_root("/dev/root.old", root_mountflags
& ~MS_RDONLY
);
46 sys_mkdir("/old", 0700);
47 root_fd
= open("/", 0, 0);
48 old_fd
= open("/old", 0, 0);
49 /* move initrd over / and chdir/chroot in initrd root */
51 sys_mount(".", "/", NULL
, MS_MOVE
, NULL
);
55 pid
= kernel_thread(do_linuxrc
, "/linuxrc", SIGCHLD
);
57 while (pid
!= waitpid(-1, &i
, 0))
61 /* move initrd to rootfs' /old */
63 sys_mount("/", ".", NULL
, MS_MOVE
, NULL
);
64 /* switch root and cwd back to / of rootfs */
69 umount_devfs("/old/dev");
71 if (real_root_dev
== Root_RAM0
) {
76 ROOT_DEV
= real_root_dev
;
79 printk(KERN_NOTICE
"Trying to move old root to /initrd ... ");
80 error
= sys_mount("/old", "/root/initrd", NULL
, MS_MOVE
, NULL
);
84 int fd
= open("/dev/root.old", O_RDWR
, 0);
86 printk(KERN_NOTICE
"Unmounting old root\n");
87 sys_umount("/old", MNT_DETACH
);
88 printk(KERN_NOTICE
"Trying to free ramdisk memory ... ");
92 error
= sys_ioctl(fd
, BLKFLSBUF
, 0);
95 printk(!error
? "okay\n" : "failed\n");
99 int __init
initrd_load(void)
104 create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR
, 0), NULL
);
105 create_dev("/dev/initrd", MKDEV(RAMDISK_MAJOR
, INITRD_MINOR
), NULL
);
106 /* Load the initrd data into /dev/ram0. Execute it as initrd unless
107 * /dev/ram0 is supposed to be our actual root device, in
108 * that case the ram disk is just set up here, and gets
109 * mounted in the normal path. */
110 if (rd_load_image("/dev/initrd") && ROOT_DEV
!= Root_RAM0
) {