initrd的工作原理

来源:互联网 发布:htc one m8刷机windows 编辑:程序博客网 时间:2024/04/28 09:27

initrd的工作原理

/dev/initrd是一个只读的block device,在the boot loader 初始化,看man initrd

linux kernel 把/dev/initrd copy到ram0中,如何mount ram0,如何执行/linuxrc. 函数如下:

initrd_setup--已经转换成了内存地址了
handle_initrd处理initrd,调用linuxrc

在linuxrc中使用

mount -o defaults --ro -t ext3 /dev/root /sysroot
pivot_root /sysroot /sysroot/initrd
把initrd 放到/sysroot/initrd
然后执行正常的启动(/sbin/init)

在rc.sysinit中umount initrd

# Unmount the initrd, if necessary
if LC_ALL=C grep -q /initrd /proc/mounts && ! LC_ALL=C grep -q /initrd/loopfs /proc/mounts ; then
if [ -e /initrd/dev/.devfsd ]; then
umount /initrd/dev
fi
action ___FCKpd___2quot;Unmounting initrd: " umount /initrd
/sbin/blockdev --flushbufs /dev/ram0 >/dev/null 2>&1 ---为了是否ram0的内存
fi