Initrd的加载过程.ppt

上传人:本田雅阁 文档编号:3481500 上传时间:2019-09-01 格式:PPT 页数:15 大小:186.52KB
返回 下载 相关 举报
Initrd的加载过程.ppt_第1页
第1页 / 共15页
Initrd的加载过程.ppt_第2页
第2页 / 共15页
Initrd的加载过程.ppt_第3页
第3页 / 共15页
Initrd的加载过程.ppt_第4页
第4页 / 共15页
Initrd的加载过程.ppt_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《Initrd的加载过程.ppt》由会员分享,可在线阅读,更多相关《Initrd的加载过程.ppt(15页珍藏版)》请在三一文库上搜索。

1、Initrd的加载过程(2.4.x),什么是 Initrd 典型的系统启动顺序 函数调用关系与代码分析,什么是 Initrd,initrd 的英文含义是 initialized RAM disk,就是由 bootloader 初始化的内存盘。在 linux内核启动前, bootloader 会将存储介质中的 initrd 文件加载到内存,内核启动时会在访问真正的根文件系统前先访问该内存中的 initrd 文件系统。,优点,把更多的内核功能条目编译成模块,减小了内核大小; 面对各种不同的硬件架构,可以使用initrd中的linuxrc按需进行模块加载以驱动硬件,从而提高kernel的可移植性。,

2、1. bootloader将内核和initrd根文件系统加载到内存中; 2. 内核初始化 ram disk 空间并把initrd根文件系统解压释放到 ram disk 中,同时释放原initrd使用的内存; 3. initrd以读写方式被挂载; 4. 执行/linuxrc(此文件可以是任何可执行文件,如脚本。此时以uid 0运行,可以做任何初始化工作); 5. 在linuxrc中挂载真正的根文件系统; 6. linuxrc使用pivot_root系统调用把根文件系统挂载在根目录; 7. 正常的启动顺序(调用/sbin/init)在根文件系统上执行; 8. initrd文件系统被移去。,使用in

3、itrd时的系统启动顺序,grub.conf示例,1 # grub.conf generated by anaconda 2 # 3 # Note that you do not have to rerun grub after making changes to this file 4 # NOTICE: You have a /boot partition. This means that 5 # all kernel and initrd paths are relative to /boot/, eg. 6 # root (hd0,6) 7 # kernel /vmlinuz-vers

4、ion ro root=/dev/hda8 8 # initrd /initrd-version.img 9 #boot=/dev/hda 10 default=0 11 timeout=10 12 splashimage=(hd0,6)/grub/splash.xpm.gz 13 title Red Hat Linux (2.4.20-8) 14 root (hd0,6) 15 kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ vga=0x0317 16 initrd /initrd-2.4.20-8.img 17 title DOS 18 rootnover

5、ify (hd0,0) 19 chainloader +1,initrd-2.4.20-8.img中的/linuxrc,init目录,内核初始化的源代码在 init目录下,在这个目录下共有三个文件 main.c do_mounts.c version.c,init(void *unused),do_basic_setup(void),prepare_namespace(),free_initmem(),initrd_load(),handle_initrd(),rd_load_image(char *from),do_linuxrc(char *shell),initrd相关调用,do_bas

6、ic_setup():对系统初始化,系统硬件此时只有cpu子系统在运转,内存管理和进程管理也开始工作了; prepare_namespace(void):决定根设备的挂载以及切换根文件系统; initrd_load(): 创建 ramdisk 设备文件,将initrd文件系统释放到 ramdisk 中去; handle_initrd(): 挂载 ramdisk 为根目录,执行 /linuxrc 脚本;,init()函数分析,static int init(void * unused) lock_kernel(); do_basic_setup(); prepare_namespace(); /

7、* * Ok, we have completed the initial bootup, and * were essentially up and running. Get rid of the * initmem segments and start the user-mode stuff */ free_initmem(); unlock_kernel(); if (open(“/dev/console“, O_RDWR, 0) 0) printk(“Warning: unable to open an initial console.n“);,init()函数分析(续),(void)

8、 dup(0); (void) dup(0); /* * We try each of these until one succeeds. * * The Bourne shell can be used instead of init if we are * trying to recover a really broken machine. */ if (execute_command) execve(execute_command,argv_init,envp_init); execve(“/sbin/init“,argv_init,envp_init); execve(“/etc/in

9、it“,argv_init,envp_init); execve(“/bin/init“,argv_init,envp_init); execve(“/bin/sh“,argv_init,envp_init); panic(“No init found. Try passing init= option to kernel.“); ,void prepare_namespace(void) . if (mount_initrd) if (initrd_load() ,根文件系统的挂载,static int _init initrd_load(void) #ifdef CONFIG_BLK_DE

10、V_INITRD create_dev(“/dev/ram“, MKDEV(RAMDISK_MAJOR, 0), NULL); create_dev(“/dev/initrd“, MKDEV(RAMDISK_MAJOR, INITRD_MINOR), NULL); #endif return rd_load_image(“/dev/initrd“); ,装入ramdisk,static void _init handle_initrd(void) . pid = kernel_thread(do_linuxrc, “/linuxrc“, SIGCHLD); if (pid 0) while (pid != wait( . ,执行初始化脚本,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1