real_root_dev = new_encode_dev(ROOT_DEV);
create_dev("/dev/root.old",Root_RAM0);
/* mount initrd on rootfs’ /root */
mount_block_root("/dev/root.old",root_mountflags & ~MS_RDONLY);
sys_mkdir("/old",0700);
root_fd = sys_open("/",0);
old_fd = sys_open("/old",0);
/* move initrd over / and chdir/chroot in initrd root */
sys_chdir("/root");
sys_mount(".",NULL);
sys_chroot(".");
/*
* In case that a resume from disk is carried out by linuxrc or one of
* its children,we need to tell the freezer not to wait for us.
*/
current->flags |= PF_FREEZER_SKIP;
pid = kernel_thread(do_linuxrc,"/linuxrc",SIGCHLD);
if (pid > 0)
while (pid != sys_wait4(-1,NULL))
yield();
current->flags &= ~PF_FREEZER_SKIP;
/* move initrd to rootfs’ /old */
sys_fchdir(old_fd);
sys_mount("/",".",NULL);
/* switch root and cwd back to / of rootfs */
sys_fchdir(root_fd);
sys_chroot(".");
sys_close(old_fd);
sys_close(root_fd);
if (new_decode_dev(real_root_dev) == Root_RAM0) {
sys_chdir("/old");
return;
}
ROOT_DEV = new_decode_dev(real_root_dev);
mount_root();
printk(KERN_NOTICE "Trying to move old root to /initrd … ");
error = sys_mount("/old","/root/initrd",NULL);
if (!error)
printk("okay\n");
else {
int fd = sys_open("/dev/root.old",0);
if (error == -ENOENT)
printk("/initrd does not exist. Ignored.\n");
else
printk("failed\n");
printk(KERN_NOTICE "Unmounting old root\n");
sys_umount("/old",MNT_DETACH);
printk(KERN_NOTICE "Trying to free ramdisk memory … ");
if (fd
error = fd;
} else {
error = sys_ioctl(fd,BLKFLSBUF,0);
sys_close(fd);
}
printk(!error ? "okay\n" : "failed\n");
}
}[/code]
先将/dev/ram0挂载,而后执行/linuxrc.等其执行完后.切换根目录,再挂载具体的根文件系统.
到这里.文件系统挂载的全部内容就分析完了.
四、小结
在本小节里.分析了根文件系统的挂载流程.并对几个虚拟根文件系统的情况做了详细的分析.理解这部份,对我们构建linux嵌入式开发系统是很有帮助的.
五、参考资料
IBM技术论坛的附根文件系统挂载流程图:
(编辑:ASP站长网)
|