In this article, we will create our own simple minimal linux distribution to understand how linux distributions work.
Installing required packages
First, before you start the build process, you need the build tools and for testing. to the public we need For this, we need to install the following packages.
apt install build-essential bison flex libc6-dev bc qemu-kvm
Obtaining source codes
source code of the Linux kernel https://kernel.org Download via.
Busybox source code https://busybox.net Download via.
Then let's open the archives we downloaded. In the last case it should be as follows.
We will obtain parts of the minimal distribution that we will create with the build operations. For this busybox first then linux core We need to compile. Compilation is performed in the directory where the source code is located. Compilations may take a little longer depending on the speed of your computer and may consume a lot of energy.
Let's compile the busybox source code first. Yet libc Because I didn't explain the part about static (Detailed information about this will be explained in the 2nd part). For this, first
make defconfig Let's use the command. Then let's open the .config file and edit it as follows.
make Let's compile using the command.
After compilation is complete busybox Our file should be created. To see if it's static ldd We can check it with the command
$ ldd busybox not a dynamic executable
Now it's time to compile the linux kernel. For this before
make defconfig using the command and then
make bzImage Let's create our kernel image with the command.
When compilation is complete Kernel: arch/x86/boot/bzImage is ready (#1) should write a line. You can use the command below to see if our kernel is compiled properly.
$ file arch/x86/boot/bzImage arch/x86/boot/bzImage: Linux kernel x86 boot executable bzImage, version 6.2.7 (email@example.com) #1 SMP PREEMPT_DYNAMIC Tue Mar 21 08:18:58 -00 2023 , RO-rootFS, swap_dev 0XB, Normal VGA
Next in the section It will be explained how to create and test initramfs using the kernel we have compiled and the busybox file.