On Sat, 3 May 2003, Werner Puschitz wrote: > > On Sat, 3 May 2003, Robert P. J. Day wrote: > > > so why is initrd.img necessary for LVs even when it has > > no modules? > > The initrd image is needed to run a few initial commands within the initrd > image (filesystem). The system loads the "linuxrc" file from the initrd > image. This file is a script which scans the disks for volume groups, BTW, if the kernel has been compiled with the CONFIG_BLK_DEV_INITRD option, which is the case with Red Hat's kernel: $ grep CONFIG_BLK_DEV_INITRD /boot/config-2.4.18-26.8.0 CONFIG_BLK_DEV_INITRD=y $ then you can see that the kernel always executes "linuxrc": /usr/src/linux-2.4/init/do_mounts.c: #ifdef CONFIG_BLK_DEV_INITRD static int do_linuxrc(void * shell) { static char *argv[] = { "linuxrc", NULL, }; extern char * envp_init[]; sys_chdir("/root"); sys_mount(".", "/", NULL, MS_MOVE, NULL); sys_chroot("."); mount_devfs_fs (); close(0);close(1);close(2); setsid(); (void) open("/dev/console",O_RDWR,0); (void) dup(0); (void) dup(0); return execve(shell, argv, envp_init); } #endif static void __init handle_initrd(void) { #ifdef CONFIG_BLK_DEV_INITRD int ram0 = kdev_t_to_nr(MKDEV(RAMDISK_MAJOR,0)); int error; int i, pid; create_dev("/dev/root.old", ram0, NULL); mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); sys_mkdir("/old", 0700); sys_chdir("/old"); pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD); if (pid > 0) { while (pid != wait(&i)) yield(); } sys_mount("..", ".", NULL, MS_MOVE, NULL); sys_umount("/old/dev", 0); ... Werner > etc. and mounts the root filesystem. For example, on my system linuxrc > runs at the end the following command: > mount -o defaults --ro -t ext3 /dev/Volume00/LogVol01 /sysroot > > You can find the script "linuxrc" in the root directory of the initrd > image. You will also see that the linuxrc script uses the script > interpreter nash(8). This is a very small interpreter which has some > important built in commands like mount, umount, etc. See man nash(8). > You can find the nash interpreter in the bin directory of the initrd > image. > > So basically, you need the initrd image for finding and mounting the root > fileystem. Here is a printout of my linuxrc script: > > #!/bin/nash > echo "Loading lvm-mod module" > insmod /lib/lvm-mod.o > echo "Loading jbd module" > insmod /lib/jbd.o > echo "Loading ext3 module" > insmod /lib/ext3.o > echo Mounting /proc filesystem > mount -t proc /proc /proc > echo Creating block devices > mkdevices /dev > echo Scanning logical volumes > vgscan > echo Activating logical volumes > vgchange -ay > echo 0x0100 > /proc/sys/kernel/real-root-dev > echo Mounting root filesystem > mount -o defaults --ro -t ext3 /dev/Volume00/LogVol01 /sysroot > pivot_root /sysroot /sysroot/initrd > umount /initrd/proc > > Werner > > > > >