Gentoo Archives: gentoo-user

From: Michael Mol <mikemol@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Making a init thingy. Step two I guess.
Date: Sat, 17 Sep 2011 22:46:12
Message-Id: CA+czFiDkQ-=SemfV5VS43Q-F7WJ3DYPZ1zZpOGUMwft3e10U0Q@mail.gmail.com
In Reply to: Re: [gentoo-user] Making a init thingy. Step two I guess. by Dale
1 On Sat, Sep 17, 2011 at 6:27 PM, Dale <rdalek1967@×××××.com> wrote:
2 > Mark Knecht wrote:
3 > I think there are only a few that has that flag, at least that I would put
4 > in the init thingy anyway.  Maybe this is something that the devs will work
5 > on if it can be done.  May be a big if there.
6 >
7 > That is the guide I am trying to go by but I think I am missing something.
8 >  This is the script they have posted:
9 >
10 > #!/bin/busybox sh
11 >
12 > # Mount the /proc and /sys filesystems.
13 > mount -t proc none /proc
14 > mount -t sysfs none /sys
15 >
16 > # Do your stuff here.
17 > echo "This script mounts rootfs and boots it up, nothing more!"
18 >
19 > # Mount the root filesystem.
20 > mount -o ro /dev/sda1 /mnt/root
21 >
22 > # Clean up.
23 > umount /proc
24 > umount /sys
25 >
26 > # Boot the real thing.
27 > exec switch_root /mnt/root /sbin/init
28 >
29 > That doesn't really make much sense to me.  First it mounts the stuff then
30 > umounts it right after that.  Huh?  Is the relevant part the "mount -o ro
31 > /dev/sda1 /mnt/root" ?  Then the exec switch_root part after that?  The rest
32 > seems to cancel each other out.
33 >
34 > Looking forward to that light bulb moment here.  ;-)
35
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 :wq

Replies

Subject Author
Re: [gentoo-user] Making a init thingy. Step two I guess. Dale <rdalek1967@×××××.com>