Gentoo Archives: gentoo-dev

From: William Hubbs <williamh@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] /usr vs. initramfs redux
Date: Sat, 06 Aug 2011 02:38:33
Message-Id: 20110806023706.GA7656@linux1
In Reply to: Re: [gentoo-dev] /usr vs. initramfs redux by Rich Freeman
1 Hi Rich,
2
3 On Fri, Aug 05, 2011 at 09:04:50PM -0400, Rich Freeman wrote:
4 > On Fri, Aug 5, 2011 at 8:42 PM, William Hubbs <williamh@g.o> wrote:
5 > > On Fri, Aug 05, 2011 at 10:06:48PM +0200, Sven Vermeulen wrote:
6 > >> How does the tool that creates an initramfs know which files to copy from
7 > >> /usr and /var anyhow?
8 > >
9 > >  My understanding is that nothing gets copied from /usr and /var, and it
10 > >  doesn't have to.
11 > >
12 > >  Here is my basic understanding of how the boot sequence works:
13 > >
14 > >  1) rootfs is mounted on /. Rootfs contains the contents of the
15 > >        initramfs.
16 >
17 > Ok, so the initfs is typically in /boot, though it need not be. It
18 > needs to be someplace the bootloader can find it, and with grub legacy
19 > that typically means on a bare hard drive partition, or one using md
20 > raid-1 with older metadata. The initramfs doesn't need to find itself
21 > - the bootloader loads it into ram and passes its address to the
22 > kernel when executing it.
23
24 Not quite. It is actually inside the kernel binary. You are thinking of
25 an initrd.
26
27 Look at these files:
28
29 /usr/src/linux/Documentation/filesystems/ramfs-rootfs-initramfs.txt.
30 /usr/src/linux/Documentation/early-userspace/README
31
32 >
33 > > 2) the init program inside  the initramfs is run.
34 > > 3) This init program will mount the real /usr and /var.
35 >
36 > So, this is the chicken and egg bit that led to the question about how
37 > the tool that creates initramfs knows what to copy from /usr, etc. If
38 > /usr can be mounted without any files from /usr, then clearly booting
39 > without /usr mounted shouldn't be a problem (just mount it early). If
40 > it does need files from /usr, then the initramfs has to contain those
41 > files since /usr isn't mounted yet.
42
43 All we are trying to do is get /usr and /var mounted before running
44 udev. All you really need in the initramfs is whatever is necessary to
45 get the file systems mounted.
46
47 > Keep in mind the initramfs does not need to fully initialize the
48 > system, and it doesn't need to do it in a way compatible with anything
49 > that will subsequently load. It doesn't need to populate /dev the way
50 > the rest of the stuff in the distro expects it to be, since the /dev
51 > it is populating will get unmounted/wiped/etc before switching roots.
52
53 Actually the /dev in the initramfs will not be wiped; it will become
54 /dev in the running system.
55
56 The other thing we will need is to have CONFIG_DEVTMPFS set to y in the
57 kernel config. This will create a tmpfs containing all devices that the
58 kernel knows about, which should be mounted on /dev. This
59 CONFIG_DEVTMPFS=y setting is also preferred by upstream udev.
60
61 > Initramfs just has to quickly operate in a scratch filesystem, mount
62 > the real filesystems, then wipe itself out and chroot. It doesn't
63 > need to be compatible with the latest version of
64 > dbus/hal/X11/openrc/etc - it just needs to be internally
65 > self-consistent.
66
67 My understanding is it doesn't do anything like a chroot. Instead, it
68 mounts the real root directly on top of itself.
69
70 > For whatever reason it still isn't working for me (using dracut) - for
71 > some bizarre reason it can't auto-detect my raid, even though running
72 > mdadm --assemble --scan and exiting the dash shell allows it to boot.
73 > Oh well - I'm sure I'll work it out. Then of course somebody needs to
74 > patch it to mount /usr as well, or grab a copy of whatever Fedora is
75 > doing if it is open source.
76
77 I think it is more simple than this; I will be looking into the steps to
78 make a trivial initramfs soon.
79
80 William

Replies

Subject Author
Re: [gentoo-dev] /usr vs. initramfs redux Mike Gilbert <floppymaster@×××××.com>