分类: LINUX
2008-03-29 22:37:46
以前一直没有用initrd.昨天想尝试U disk上的linux系统。所以就用了initrd
在recomplie kernel的时候,就把ext2、ext3全部modules了。
没想到报这个错。
unable to mount root fs on unknown-block
网上说2.6.*的kernel要把ext2、ext3全部build-in.
照做了,又产生了initrd文件。
------------------mkinitrd的用法----------------------------
mkinitrd /boot/initrd-2.6.17-gentoo-r4 2.6.17-gentoo-r4
------------------over--------------------------
结果重启后又出现这个报错:
---------------booting error message-------------
EXT3-fs:mounted filesystem with ordered data mode
pivotroot:pivot_root(/sysroot,/sysroot/initrd)failed:2
umount /initrd/proc failed:2
Freeing unused kernel memory:124k freed
kernel panic - not syncing: No init found. Try passing init=option to kernel.
----------------error message over--------------
通过error message的第一行已经知道了,系统对ext3的支持已经到位了。
一个小学语文没过关的人说ext2、ext3不能同时build-in,否则出现此报错。
报着试一试的想法,我将ext3 modules,将ext2 build-in(因为initrd为ext2,故必须build-in)
结果出现以下报错:
---------------error message--------------------
Mounting root filesystem
mount:error 19 mounting ext3
pivotroot:pivot_root(/sysroot,/sysroot/initrd) failed:2
umount /initrd/proc failed;2
Freeing unused kernel memory:124k freed
kernel panic - not syncing:No init found.Try passing init= option to kernel
--------------error message over----------------
此人没出现报错,估计可能是文字表达时没说清楚,真是害死人,拖出去斩了才好。误导观众!
于是又将ext2、ext3全部build-in.
俺寻遍google、baidu.最终找到个贴子,高人说:
----------------高人say-------------------------
mkdir /initrd
failed:2后面还有个2呢!2就是出错的含义。
应该说很多问题都会提示No init found.
Try passing init= option to kernel.
但pivotroot出错99%是没有initrd目录造成的。
可以肯定一点ext3的模块没有问题,ext3的模块可以不在内核中而被正确使用,它通过initrd进行加载的
---------------高人say over---------------------
开始我还傻傻的以为要在initrd文件里去建initrd目录,发现还是不行,
后来一想,initrd根文件系统已经挂载了,那么在挂载的情况下报错,
应该在real root filesystem里解决呀。
于是乎:
mkdir /initrd
reboot.解决!哈哈
*********************************华丽的分界线*********************************
the 2.6.* kernel complie mothod:
make
make modules
make modules_install
make install
可以说,只要玩kernel就会碰到“unable to mount root fs on unknown-block”错误,这个报错不知害了多少人。。。。觉得这个老外对于这个问题的思路比较清晰:
First,
check the File system type drivers in new kernel, and make sure the
file system drivers you will use are compiled into kernel not in
modules.
Second, check the "Block Devices->Ram file system support" and "File systems -> Miscellaneous filesystems -> Compressed ROM file system support" are selected and compiled into kernel.
Third, check the ATA IDE drivers that your hardwares will use are compiled into kernel.
补充:在Block devies里还有一个Loopback device support需要build-in
这是因为gentoo里initrd的文件是以loopback的方式来挂载的,所以需要加上。
当然fedora core3以后是用cpio方式来搞的。另当别论。
mkcramfs utility creates an image of a cramfs filesystem
mkinitrd utility creates an images of a ext2 filesystem
制作启动盘里的root filesystem和正常pc上的root filesystem是不一样的
前者需要一个完整的root filesystem运行环境,lib/etc下都需要有东西,才可能enbale一个完整的linux mini系统
而后者仅仅需要insmod等命令,它只是一个brige的作用,过度的、临时的,由于它的存在才会让real root system正常工作。
在IBM网站上搜到一个文章,关于RAM Disk讲得很清楚,可谓一扫疑云。
----------------About initrd-------------------
description of initial RAM disk(initrd)
The Linux® initial RAM disk (initrd) is a temporary root file system that is mounted during system boot to support the two-state boot process. The initrd contains various executables and drivers that permit the real root file system to be mounted, after which the initrd RAM disk is unmounted and its memory freed.
The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real root file system is available. The initrd is bound to (be bound to 一定要)the kernel and loaded as part of the kernel boot procedure. The kernel then mounts this initrd as part of the two-stage boot process to load the modules to make the real file systems available and get at the real root file system.
The initrd contains a minimal set of directories and executables to achieve this, such as the insmod tool to install kernel modules into the kernel.
In the case of desktop or server Linux systems, the initrd is a transient(短暂) file system. Its lifetime is short, only serving as a bridge to the real root file system.
Anatomy(剖析) of the initrd
Depending on which version of Linux you're running, the method
creating the initial RAM disk can vary.Prior to Fedora Core 3, the
initrd is constructed using the loop device. The loop device is a
device driver that allows you to mount a file as a block device and
then interpret the file system it represents. The loop device may not
be present in your kernel, but you can enable it through the kernel's
configuration tool (make menuconfig) by selecting Device Drivers >
Block Devices > Loopback Device Support. You can inspect the loop
device as follows (your initrd file name will vary):
Listing 1. Inspecting the initrd (prior to FC3)
# mkdir temp ; cd temp
# cp /boot/initrd.img.gz .
# gunzip initrd.img.gz
# mount -t ext -o loop initrd.img /mnt/initrd
# ls -la /mnt/initrd
#
You
can now inspect the /mnt/initrd subdirectory for the contents of the
initrd. Note that even if your initrd image file does not end with the
.gz suffix, it's a compressed file, and you can add the .gz suffix to
gunzip it.
Beginning with Fedora Core 3, the default initrd image is a compressed cpio archive file. Instead of mounting the file as a compressed image using the loop device, you can use a cpio archive. To inspect the contents of a cpio archive, use the following commands:
Listing 2. Inspecting the initrd (FC3 and later)
# mkdir temp ; cd temp
# cp /boot/initrd-2.6.14.2.img initrd-2.6.14.2.img.gz
# gunzip initrd-2.6.14.2.img.gz
# cpio -i --make-directories < initrd-2.6.14.2.img
#
The
result is a small root file system, as shown in Listing 3. The small,
but necessary, set of applications are present in the ./bin directory,
including nash (not a shell, a script interpreter), insmod for loading
kernel modules, and lvm (logical volume manager tools).