Gentoo Archives: gentoo-user

From: Dale <rdalek1967@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Making a init thingy. Step two I guess.
Date: Sun, 18 Sep 2011 02:14:41
Message-Id: 4E7553C8.8080508@gmail.com
In Reply to: Re: [gentoo-user] Making a init thingy. Step two I guess. by Michael Mol
1 Michael Mol wrote:
2 > On Sat, Sep 17, 2011 at 6:27 PM, Dale<rdalek1967@×××××.com> wrote:
3 >> Mark Knecht wrote:
4 >> I think there are only a few that has that flag, at least that I would put
5 >> in the init thingy anyway. Maybe this is something that the devs will work
6 >> on if it can be done. May be a big if there.
7 >>
8 >> That is the guide I am trying to go by but I think I am missing something.
9 >> This is the script they have posted:
10 >>
11 >> #!/bin/busybox sh
12 >>
13 >> # Mount the /proc and /sys filesystems.
14 >> mount -t proc none /proc
15 >> mount -t sysfs none /sys
16 >>
17 >> # Do your stuff here.
18 >> echo "This script mounts rootfs and boots it up, nothing more!"
19 >>
20 >> # Mount the root filesystem.
21 >> mount -o ro /dev/sda1 /mnt/root
22 >>
23 >> # Clean up.
24 >> umount /proc
25 >> umount /sys
26 >>
27 >> # Boot the real thing.
28 >> exec switch_root /mnt/root /sbin/init
29 >>
30 >> That doesn't really make much sense to me. First it mounts the stuff then
31 >> umounts it right after that. Huh? Is the relevant part the "mount -o ro
32 >> /dev/sda1 /mnt/root" ? Then the exec switch_root part after that? The rest
33 >> seems to cancel each other out.
34 >>
35 >> Looking forward to that light bulb moment here. ;-)
36 > Here's how I read it.
37 >
38 > First, it mounts /proc and /sys, since just about anything is going to
39 > need at least one of those.
40 >
41 > Second, it mounts your (desired) / filesystem at /mnt/root.
42 >
43 > Third, it unmounts /proc and /sys.
44 >
45 > Fourth, it switches out / with the filesystem it already mounted at
46 > /mnt/root. This is similar (idential) to chroot. At the _same_ time,
47 > it launches your init script.
48 >
49 > Your init script launches and sees a / without a /proc or a /sys. The
50 > / it sees is what _was_ /mnt/root only moments before. The stuff that
51 > was originally at / is no longer accessible. (Which, incidentally, is
52 > why you unmount /proc and /sys; nothing would be able to get to those
53 > particular mounted filesystems, since everything else gets to see the
54 > world with /mnt/root/ as the /.
55 >
56 > Your init script (the one at /sbin/init), seeing itself in a fresh,
57 > needs-to-be-booted system, mounts /proc, /sys, etc...everything the
58 > init script is configured to do.
59 >
60
61 Ahhhhh. I see now. So, it mounts proc and sys but that is in the init
62 then it mounts the real root outside the init. Then it umounts the proc
63 and sys under the init and then switches to the real root and starts
64 init there.
65
66 Where does /usr and /var come in here? Isn't the init supposed to mount
67 that too? Do I add that myself? If so, when to fsck get ran?
68
69 Dale
70
71 :-) :-)

Replies

Subject Author
Re: [gentoo-user] Making a init thingy. Step two I guess. Michael Mol <mikemol@×××××.com>
Re: [gentoo-user] Making a init thingy. Step two I guess. Mark Knecht <markknecht@×××××.com>