Updated April 20, 2023
Introduction to Linux From Scratch
The concept of Linux From Scratch is an installation in Linux which will install a full-fledged Linux system by building all the components of the Linux system manually. As we can purely understand that the making of Linux from scratch is a much longer process than actually install a Linux distribution in the system, but with this it brings the customization that might be required for the Linux which gets installed. The flexible, compact and secure system will be as per the requirement of the user and no extra components would be present and will also enable user or developer to learn how Linux systems work internally. With this, in this article, we will see the procedure to install and how this component works in general in a development environment.
Requirements and Procedure
Here we will go through the requirements which is necessary for building your own Linux from scratch. The list of all the software are mentioned in the book Linux from scratch including the minimum version which is mentioned so that the Linux build is spotless.
The list is as follows:
Now, once the requirement is fulfilled, following steps are followed.
Here, we would also see about any specific syntax that would be required for fulfilling the build.
- In the current operating system, or the Virtual Box or VM, a partition is created and then the correct file format is set up. Basic directories like the bin folder, the place where binaries of the files need to be installed, usr folder where the user related data resides etc. are created and kept ready.
- The compressed source code which is available on GitHub or any private repository is downloaded as .tar.gz or .tar files.
- While downloading the tar file, one needs to keep in mind to verify the integrity of the tarball by doing a hash check to look for any tampering in the compressed file.
- The compressed file is extracted for getting the source code for the desired process or command’s source code.
- make command (syntax: make check) is run to perform a check on the source code. Post that (syntax: make install) is run for building and installing the required process and store the binaries in the bin folder.
- The steps 2 to 5 is repeated for any other command or process that one would need to install in the Linux system.
How does Linux From Scratch work in Linux?
In Linux from scratch it is undoubtedly about understanding the working of LFS-Bootscripts. These Bootscripts are installed as a part of the Step 5. LFS-Bootscripts are a set of scripts which are installed in order to perform some basic yet important tasks. These SysV type scripts performs various tasks like performing check on the filesystem integrity during boot, loading of keymaps, setting up of networks, and halting process in case of shutdown. These, although looks primal tasks, but are equally important for smooth functioning of the Linux system.
Before we see the working, it is imperative to know about the different set of scripts which are installed as a part of LFS-Bootscripts.
Given below we have some set of scripts which are basic yet the most important ones.
- checkfs: Looks for any issues in a file system before they are mounted.
- cleanfs: Removes any files which need not be preserved between reboots.
- halt: Helps in halting the system.
- network: Helps in setting up of network interfaces.
- localnet: Makes sure that hostname and local device for loopback is correctly set up.
- reboot: Helps in rebooting the system.
- halt: Helps in halting the system.
The above list is not exhaustive, and reader should be mindful of the same.
Now that we have a brief idea on what Bootscripts are, let us know on how these Bootscripts work? The booting facility of Linux is a special one which is known as SysVinit and the running concept is based on run-levels. Here, there are 7 run-levels where each of these level corresponds to a state and also refers to the actions that needs to be performed when the operating system starts up.
The run-levels are as follows.
- 0: To halt the computer.
- 1: Allow only a single user.
- 2: Allows multiple users but with no networking.
- 3: Allows multiple users with networking.
- 4: Placeholder for any customized option.
- 5: Again, a placeholder but most likely used for logging in using GUI.
- 6: To reboot the computer.
Using init command one can easily modify the run levels as per the requirement of the use case. In the location /etc/rc.d there are numerous files present like rc?.d where? signifies the run level one is looking for. This also consists of rcsysinit.d which contains symbolic links having a nomenclature which helps in determining the order in which the scripts in the directory needs to run in. The lower the number in the nomenclature the earlier the file gets executed.in the folder /etc/rc.d/init.d the actual scripts are stored. The symbolic links points to the scripts stored here, and these are the scripts which does the entire work as desired by the developer.
This is where, the customization kicks in, one can choose the lifestyle it needs for its Linux system by choosing the way the boot process works. After all this is one’s own system where one can put all creativity to bring something to life.
In this article though there is no example, but nevertheless the article focusses on a project named Linux from Scratch (LFS) and how one can build customized Linux system which can suits one’s requirement and is free of any unwanted components in the Linux system getting developed. There are above and beyond LFS, for example, BLFS (Beyond Linux From Scratch), ALFS (Automated Linux From Scratch) etc. which is outside the scope of the article, but is a preferred read for our readers.
This is a guide to Linux From Scratch. Here we discuss the introduction, requirements and procedure, how does linux from scratch work in linux? You may also have a look at the following articles to learn more –