Justin R. Knierim wrote:
Hi Alexander or anyone else who can answer this ;),
I was just wondering something. For device mapper, we start with creating
the root.ext2 filesystem and then it would appear that we build and
install directly to it. Seems fine, but is there not a reason one could
build like in the unionfs livecds, to the normal /mnt/lfs directory, and
then afterwards create the root.ext2 file and copy the files to it? I'm
sure I am missing something obvious, but not sure what. From the
keep-as-many-sectors-zero-as-possible standpoint, it would be an
improvement if I understand correctly.
This would also work. Currently, less than a megabyte is wasted by
building directly on root.ext2 (as you can check by running "make
zeroes" and recompressing the ISO), but the requirement for the size of
the LFS partition is reduced.
Anyways, if you could give a brief rundown of how this works, that would
be helpful. Just trying to figure out some errors in the cross branch,
which I likely put in there, and need to sit down and examine things well.
:)
Brief rundown of the build procedure:
The Makefile bind-mounts everything that is necessary for the build, but
should not be on the final CD. Then it builds everything on root.ext2
and cleans up. End result: full LFS on root.ext2. Then "mkzftree" is
used to compress root.ext2 and burn it on the CD together with a kernel
image and initramfs. It is important that the "-z" flag is passed to
mkisofs, otherwise the resulting image is not recognized as a compressed
image by the kernel.
Brief rundown of the boot procedure:
The initramfs finds the CD (/dev/lfs-cd) by label, and does the
following mounts (I write the equivalent bash script instead of the C code):
mount -n -t proc proc /proc
mount -n -t iso9660 /dev/lfs-cd /.cdrom
mount -n -t tmpfs tmpfs /.tmpfs
losetup /dev/loop0 /.cdrom/root.ext2
make a big sparse file as /.tmpfs/.overlay
losetup /dev/loop1 /.tmpfs/.overlay
echo 0 `blockdev --getsize /dev/loop0` snapshot /dev/loop0 /dev/loop1 p
8 | dmsetup create lfs-cd
umount /proc
Result: /dev/mapper/lfs-cd contains the same bytes as root.ext2, but is
rw. Any data written there end up in /.tmpfs/.overlay.
mount -n -t ext2 /dev/mapper/lfs-cd /.root
mount --move /.tmpfs /.root/dev/shm
Result: the overlay is /.root/dev/shm/.overlay
cd /.root
mount --move . /
exec chroot . /sbin/init "$@"
This is the standard procedure for changing from initramfs to the target
filesystem. Now the overlay is /dev/shm/.overlay. Important: the udev
bootscript must be modified in order to avoid mounting tmpfs on /dev,
and /dev/shm must not be in /etc/fstab (the tmpfs is still there, see
above). Otherwise, the overlay will become hidden and clean shutdown
will become impossible. The rest of the boot procedure is completely
standard.
Shutdown procedure:
This relies on patched sysvinit. The patch allows "init u" to be
executed even in runlevels 0 and 6. The normal shutdown and reboot
bootscripts are removed, and the shutdown helper is invoked from inittab
as the last thing in these runlevels. This helper copies some files to
/dev/shm so that one an chroot there. Just before the pivot_root line,
the situation is:
/ = what's on root.ext2
/dev/shm = tmpts
/dev/shm/.overlay exists
/dev/shm/old is empty
/dev/shm/sbin/init is a shell script
/dev/shm/dev/initctl is a dangling symlink to /old/dev/initctl
/sbin/init is still running as the process ID 1
Just after the pivot_root:
/ = tmpfs, what was earlier as /dev/shm (unstable)
/old = what was in /, i.e. on root.ext2 (unstable)
/old/sbin/init still runs as process ID 1 and listens to
/old/dev/initctl and keeps /old busy
(unstable = absolute chdir leads to strange results)
After "exec chroot . /old/sbin/init u", the "unstable" comment goes
away. Init reexecs what it thinks is itself, i.e. /sbin/init. But that's
our shell script, not the real init! It waits for /old/sbin/init to
terminate, thus making the /old mount point (i.e., root.ext2) unused.
Then everything is cleaned up and unmounted, the CD is ejected, and the
computer is powered down or rebooted.
--
Alexander E. Patrakov
--
http://linuxfromscratch.org/mailman/listinfo/livecd
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page