How to Build Your Own Minimal Linux System from Scratch
This step‑by‑step guide explains how to trim an existing Linux installation, partition a new disk, install GRUB, copy kernel and essential binaries, and finally create a bootable, network‑enabled custom Linux system using CentOS 6.9 as an example.
Introduction
Since Linux was created on October 5, 1991, its open‑source nature has attracted many developers. This article shows how to trim an existing Linux system to create a small, self‑contained Linux that includes common functions.
Principles
Brief overview of the Linux boot process: POST self‑test, BIOS disk selection, MBR bootloader, kernel loading, init process, and welcome screen. It also explains initrd (used in CentOS 5) and initramfs (used in CentOS 6) and how init uses /etc/inittab and the /etc/rc.d/rc.sysinit script.
Design Idea
1. Add a new hard disk /dev/sdb to the host, partition it into /boot and /, format it, then later treat it as /dev/sda in the new system. 2. Copy all required files to the new disk and install GRUB. 3. Copy kernel and initramfs files. 4. Use a script to copy essential binaries (ls, ifconfig, bash, reboot, rm, modprobe, mount, ip, mkdir, touch, cat, vi, less, shutdown, insmod). 5. After these steps the custom Linux is ready.
Step‑by‑Step Procedure
Using CentOS 6.9 as an example:
Partition the target disk with fdisk and format the partitions.
Create mount point /mnt/boot and mount the partitions.
Install GRUB with grub‑install --root‑directory=/mnt and verify the installation.
Copy kernel and initrd files to /mnt/boot.
Create grub.conf according to the kernel version, disable SELinux, and set the init parameter.
Create the root filesystem under /mnt/sysroot, mount it, and copy essential binaries via a script.
Copy the network driver module into the new root filesystem.
Images illustrate each command and partition layout:
Boot Test
Create a new virtual machine, replace its default disk with the prepared /dev/sdb (now /dev/sda), and boot. Successful boot confirms the custom system works.
Network Enablement
Copy the network driver module, place it under /mnt/sysroot, and test connectivity with ping from another machine. Ping succeeds, confirming network functionality.
All steps completed; the custom Linux system boots and can access the network.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
