Hi Rich,

On Fri, Aug 05, 2011 at 09:04:50PM -0400, Rich Freeman wrote:
> On Fri, Aug 5, 2011 at 8:42 PM, William Hubbs <willi...@gentoo.org> wrote:
> > On Fri, Aug 05, 2011 at 10:06:48PM +0200, Sven Vermeulen wrote:
> >> How does the tool that creates an initramfs know which files to copy from
> >> /usr and /var anyhow?
> >
> >  My understanding is that nothing gets copied from /usr and /var, and it
> >  doesn't have to.
> >
> >  Here is my basic understanding of how the boot sequence works:
> >
> >  1) rootfs is mounted on /. Rootfs contains the contents of the
> >        initramfs.
> 
> Ok, so the initfs is typically in /boot, though it need not be.  It
> needs to be someplace the bootloader can find it, and with grub legacy
> that typically means on a bare hard drive partition, or one using md
> raid-1 with older metadata.  The initramfs doesn't need to find itself
> - the bootloader loads it into ram and passes its address to the
> kernel when executing it.

Not quite. It is actually inside the kernel binary. You are thinking of
an initrd.

Look at these files:

/usr/src/linux/Documentation/filesystems/ramfs-rootfs-initramfs.txt.
/usr/src/linux/Documentation/early-userspace/README

> 
> > 2) the init program inside  the initramfs is run.
> > 3) This init program will mount the real /usr and /var.
> 
> So, this is the chicken and egg bit that led to the question about how
> the tool that creates initramfs knows what to copy from /usr, etc.  If
> /usr can be mounted without any files from /usr, then clearly booting
> without /usr mounted shouldn't be a problem (just mount it early).  If
> it does need files from /usr, then the initramfs has to contain those
> files since /usr isn't mounted yet.
 
 All we are trying to do is get /usr and /var mounted before running
 udev. All you really need in the initramfs is whatever is necessary to
 get the file systems mounted.

> Keep in mind the initramfs does not need to fully initialize the
> system, and it doesn't need to do it in a way compatible with anything
> that will subsequently load.  It doesn't need to populate /dev the way
> the rest of the stuff in the distro expects it to be, since the /dev
> it is populating will get unmounted/wiped/etc before switching roots.

Actually the /dev in the initramfs will not be wiped; it will become
/dev in the running system.

The other thing we will need is to have CONFIG_DEVTMPFS set to y in the
kernel config. This will create a tmpfs containing all devices that the
kernel knows about, which should be mounted on /dev. This
CONFIG_DEVTMPFS=y setting is also preferred by upstream udev.

> Initramfs just has to quickly operate in a scratch filesystem, mount
> the real filesystems, then wipe itself out and chroot.  It doesn't
> need to be compatible with the latest version of
> dbus/hal/X11/openrc/etc - it just needs to be internally
> self-consistent.

My understanding is it doesn't do anything like a chroot. Instead, it
mounts the real root directly on top of itself.

> For whatever reason it still isn't working for me (using dracut) - for
> some bizarre reason it can't auto-detect my raid, even though running
> mdadm --assemble --scan and exiting the dash shell allows it to boot.
> Oh well - I'm sure I'll work it out.  Then of course somebody needs to
> patch it to mount /usr as well, or grab a copy of whatever Fedora is
> doing if it is open source.

I think it is more simple than this; I will be looking into the steps to
make a trivial initramfs soon.

William

Attachment: pgpbEMn5q04l0.pgp
Description: PGP signature

Reply via email to