Saturday, June 27, 2009

Linux From Scratch

Last year I successfully built a Linux from scratch system by following the book. The date was April 24th and it took roughly 3 days to complete. I remember the process being relatively laborious. The system is only for those whom want to see how it all fits together.

I haven't touched it since then. Only off and on doing some research into boot disks, root disks, loopback devices, etc. What is interesting to me is the differences between ISOLINUX and my LFS system. I'm intrigued at how a LiveCD can give you roughly the same thing without the "installation" process as a normal distribution. Why install (30 minutes or so) when you can copy? Maybe it takes the same amount of time ... but anyway, it's for the learning experience.

From the grub command:

grub> root (hd0,3)
grub> kernel /boot/isolinux/linux root=iso:/dev/hda4:/root/lfslivecd-x86-6.3-r2160.iso rootfstype=ext2
grub> initrd /boot/isolinux/initramfs_data.cpio.gz
grub> boot

From this command the kernel is loaded into memory, the kernel mounts the initial RAM disk and finally the initial RAM disk performs a pivot root and mounts the ISO image as root and eventually provides you with a terminal. Fascinating. Generally my description is correct but there are gaps in my understanding.

Here is some of the information I've gathered from the process.

1. The second part of the kernel command (grub command), i.e. root=iso: ...
is passed to the kernel to load as a boot parameter. In other words after the kernel is loaded it will look to this boot parameter in which to mount the root filesystem.
2. But the initrd is loaded first as a preliminary root filesystem.
3. Somehow the kernel and the initrd work in tandem to know what to do with the boot parameter that I listed at #1.

How #3 happens I don't know. Reason being is that I've replaced the root=iso: ... part with a simple root filesystem on disk (instead of the ISO). It doesn't work.
Why? What is compiled in the linux kernel from the LFS disk that won't allow it to accept a regular uncompressed root filesystem on disk? What make an ISOLINUX unique from a regular compiled Linux kernel? What does the ISOLINUX kernel have to do with with the ISO9660 El Torito file system?

Maybe I just answered my own question. ISOLINUX kernel understands the El Torito (CD ROM) filesystem. So it knows how to mount the ISO image. Whereas a normal root filesystem is an EXT2 filesystem. In order for our generic ISOLINUX kernel to mount an EXT2 filesystem we would have to tell the init RAM disk how to install the kernel module in order to finally mount the root filesystem.

Once I figure out how to install modules from the init RAM disk environment I will be able to run a generic kernel from anywhere, everywhere I go.

The goal for me is to build a Linux Live USB. And not merely following the instructions provided by a website.

No comments: