initrd, /dev/root, VFS, 2.4.19 hell :(

Richard Lightman richard at nezumi.plus.com
Wed Oct 23 03:45:41 PDT 2002


* martial daumas <martial at nasgaia.org> [2002-10-23 10:43]:
> 
> Here's where I'm stuck... If someone managed to run an initrd with
> linux-2.4.18(or +, i tested 2.4.19-pre11 with same troubles), please
> point me to the right solution. I'm almost sure i missed some _basic_
> reading somewhere, so don't flame me please ;o)
> 
I use initrd set up a root partition on a logical volume. I use
kernel 2.4.20-pre8, devfs and grub patched for logical volumes. I have
read about several methods to use initrd's and pivot_root, and had
problems with all of except this:

# /boot/grub/menu.lst:
...
title stable
root <urusai:stable>
kernel /lib/modules/2.4.20-pre8/bzImage video=aty128fb:noaccel,1800x1350-24 at 85
initrd /boot/initrd.gz
...
The patch I use for grub has makes it understand <urusai:stable> as
logical volume group urusai, volume stable. Next: the impossible:

# rdev /lib/modules/2.4.20-pre8/bzImage
Root device /dev/urusai/stable

Without the initial ram disk, this would go badly wrong. Logical
volumes cannot be used until they have been setup with user space
tools. Here is how the initrd is prepared:

mkdir -p dir/{dev,etc,proc,root,tmp}
cp lvmboot dir/linuxrc
genromfs -f initrd -d dir
gzip -c9 <initrd >initrd.gz

For this to work, the kernel must have support for romfs (and initial
ramdisks) compiled in. lvmboot is a program written in C. The important
bit is here:

// vgscan & vgchange require /proc
// do_or_die does some library function, detects and errors, and exits if there is an error
do_or_die(mount, "proc", "/proc", "proc", MS_MGC_VAL|MS_NODEV|MS_NOEXEC|MS_NOSUID, "");
// vgscan & vgchange crap in /etc, and the crap is needed on the (new) root filesystem.
do_or_die(mount, "tmp",  "/tmp", "tmpfs", MS_MGC_VAL|MS_NODEV|MS_NOEXEC|MS_NOSUID, "");
do_or_die(mkdir, "/tmp/lvm", 0700);
do_or_die(mount, "/tmp/lvm", "/etc", "bind", MS_MGC_VAL|MS_BIND|MS_NODEV|MS_NOEXEC|MS_NOSUID, "");
// I have incorporated the user spece tools into lvmboot:
if (vgscan_main(  sizeof(vgscan  )/sizeof(*vgscan)  -1,   vgscan)) exit(EXIT_FAILURE);
if (vgchange_main(sizeof(vgchange)/sizeof(*vgchange)-1, vgchange)) exit(EXIT_FAILURE);
// It is now possible to mount /dev/urusai/stable, tidy up:
do_or_warn(umount, "/etc");
do_or_warn(umount, "/proc");
// lvmboot exits

Instead of the abouve, you want something to load some modules (I have
the lvm code compiled in). Note that linuxrc is not run as init, so
pivot_root will not help you in a linuxrc. Also the kernel option
init=... applies after linuxrc and the kernel's pivot_root. If you
want to run init from an initrd, you must specify the initrd as your
root device.

Here is what you get after the kernel's pivot_root:
/dev/urusai/stable at /root, and does the pivot root. Afterwards:
/dev/urusai/stable mounted at /
devfs              mounted at /dev
initrd             mounted at /initrd/
tmpfs              mounted at /initrd/tmp

The kernerl starts init. From there, the final bit of tidying can be
done with normal commands. To summerise:
mount /var
cp -r /initrd/tmp/lvm /var/lib/misc
umount /initrd/tmp /initrd

The crap is accessed via symlinks:
ln -s /var/lib/misc/lvm/lvmtab /etc/lvtab
ln -s /var/lib/misc/lvm/lvmtab.d /etc/lvtab.d

> ps: i can post my linuxrc if needed
> 
A good idea, but not here are we are a bit off topic. If it is big,
send it to me, otherwise, I am on lfs-chat and blfs-support. It would
help a lot if you said what the root partition is on.

Richard
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-support' in the subject header of the message



More information about the lfs-support mailing list