Linux From Scratch
2 Nov 2024 Linux shellpackage managementI got to know Linux From Scratch soon after I bought my desktop machine. My first attampt failed at making gcc to setup the “cross-compile” environment. About four years later I picked it up and finally went through my first pass of building LFS. My destop machine has been running LFS happily since then. Two experiences are briefly note down: 1) break dependency circle with building twice; 2) reconfig kernel and build with additional modules.
The LFS book is really detailed and well-explained. All I needed is to type the commands without typo. It seems more like a repeating work to me so I do not feel I learn something from this process. But I know it was not. I would have such a feeling is because I had some experince on building libraries, resolving dependencies, linking and installing tools during the four years. If I did not give up four years ago and sticked to the end, I would have learnt those from LFS and there would be many things to write down in this post. Anyways, going through LFS still means something to me: it is managable to build a Linux system from scratch, and my machine should be my stage to try out whatever!
I tried BLFS (Beyond LFS) a bit as well, initially wanted to bring up a GUI. However, after getting the network manager working with Wi-Fi, I shifted my focus to other projects. So in the future, as using my LFS build or trying to bring up the GUI, I might write more posts on this topic.
In this post, there are only two experiences I would like to briefly note down.
Break the Dependency Circle with Building Twice
A trick that has been used over and over again in the LFS book is building twice to break denepdency circle. Often those dependecies are not “true” dependency. It is like Package A depends on Package B, while Package B will not have full functionality if Package A is not installed. So usually we could build a partially-functioning Package B first without Package A (it might requires some build config or a placeholder of Package A to avoid failing the build when Package A is not found). Then install Package B and build Package A. Once Package A is installed, rebuild Package B with the missing part enabled and install the complete build of Package B.
Reconfig Kernel and Build with Additional Modules
It is actually not that difficult to reconfig the kernel.
The command make menuconfig would use Kconfig to bring up an interface to
adjust the kernel parameters easily.
The output config file are in the simple key-value pair format,
so you can search and edit.
The BLFS book lists the kernel dependency for packages clearly with which
key should be what value with some hiearchical structures for easier navigate
down through the menu.
I was first trying to go through the packages I planned to install to have
a full list of kernel config in order to avoid reconfig and rebuild the kernel.
But eventually, I had to reconfig and rebuild for missing kernel modeuls a few
times for network driver, USB firmware and so on.
Surprisingly, I found rebuilding kernel takes less time than I thought,
especially if I just need an additional module.
Credits
- Linux From Scratch this is where all it starts
