Last week, I decided to try to build linux from scratch, which means compiling it (the Linux kernel) from the source code. I was so excited about what I would face and I believed keeping track of what I did in a blog series was a good idea. So let’s jump to it!
First, I would assume the readers had tried using any OS that has Linux kernel before (except Android, which is pretty much so different now). After using some Linux distros, you will have a taste of what does Linux do and will understand what I’m talking about in this blog series.
In order to start doing this project, I need to follow a guide, which is called “Linux from scratch” itself: Welcome to Linux From Scratch!. If you are also interested in doing this project as well, you can follow that book as well as my series for some interesting discovery.
(Note: I will call Linux from Scratch as LFS for short)
I. Prepare the environment.
You need a Linux distro to start building LFS by your own (what an irony, but still). This is because the pre compiled Linux distro has some essential compiler, linker,… we need to build the very core of the Linux kernel. Well, if we are “guru” enough, we can write it our own and discard the pre compiled Linux distro, but that is not the point of this blog series. I don’t know anything about Assembly anyway to build these kinds of tools.
I chose Debian 8.x as the host environment, as the suggestion from the book. For me, Debian is easier to use than Gentoo, Slackware,… Actually, wandering some forums to find help building LFS, some more user-friendly Linux distros such as Linux Mint and Ubuntu is also possible to be the host environtment for building LFS.
Setting up Debian or any modern Linux distro is easy, I just need to follow the instruction in the Live CD Install. Note that I just use a VM to do this project, but the experience will be pretty much the same as in a real computer.
I booted into Debian. The book provided a pre-written version-check.sh file. This is used for checking some essential binaries and settings (symlinks) before I should proceed. This is required because in the later part of the book, it would assume these settings to be available. After version checking is completed, I proceeded to check 3 vital C library, which is gmp, mpfr and mpc (you can easily Google those). Unfortunately, they are not available. I had to go to these library’s website and download the source code to compile. However, after installing these library, the checker still said it could not find those libraries. Googling times again, some guy on LFS Forum said I need to link these lib from /usr/local/lib to /usr/lib. Problem solved!
The next thing I did is to make new partitions for my new soon-to-be LFS system. I restart my VM to boot into the Debian live CD again to do the partitioning. I set 10GB for root partition (ext4 system file) as the book suggest and 100MB for /boot partition (ext2 system file). Then I restart the VM again to enter Debian.
Those just-made partitions should not be pre mounted to Debian system, I then create LFS variable ($LFS) = /mnt/lfs and mount the root partition of new soon-tobe LFS system to $LFS. The reason why we need to use $LFS variable is that it would make the compiling and setting up easier, saving time (we can just tyle $LFS instead of /mnt/lfs everytime).
II. Proceeding to the building of LFS
In this section, currently there are nothing interesting to talk about, as the book provided very clear, even to the smallest detail why this and that happens and is necessary. Only one thing I would like to note here is to read carefully what the book put into Caution box (with Red borders) and some explanation note in Black borders. Anyway, reading carefully line by line will do most of the job. Eventually I am a newbie the LFS, being ignorant to what the author provided is stupid.
This is all I want to note in my LFS journey, as I am currently still building the Core Linux system stuff. Any comments and shares are appreciated!