Operations 9 min read

How to Build Your Own Minimal Linux System from Scratch

This step‑by‑step guide explains how to create a custom minimal Linux distribution by adding a new hard drive, partitioning it, installing GRUB, copying the kernel, initramfs and essential utilities, and finally testing the boot and network functionality on a CentOS 6.9 host.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build Your Own Minimal Linux System from Scratch

Introduction

Since its birth on October 5, 1991, the Linux operating system has attracted many developers because of its open‑source nature, and countless contributors have built a rich ecosystem that provides an excellent learning and research environment.

This article shows how to trim an existing Linux system and assemble a tiny, self‑made Linux that includes common basic functions.

Principle

The Linux boot process consists of the following steps:

POST self‑test checks hardware for faults.

If multiple boot disks exist, the BIOS selects the boot device.

The bootloader in the MBR (e.g., GRUB) is executed.

The kernel image is loaded.

The init process (the ancestor of all processes) starts.

A welcome screen is displayed.

During kernel loading, two auxiliary images are used: initrd – a memory‑based disk used in CentOS 5. initramfs – a memory‑based file system used in CentOS 6.

Init reads /etc/inittab and then runs the system initialization script /etc/rc.d/rc.sysinit.

Idea

1. Add a new hard disk /dev/sdb to the host, create two partitions ( /boot and /), and format them. After the setup, the disk will be removed and used as /dev/sda in the new system.

2. On /dev/sdb build an independent Linux system, copy all required files one by one, and install the GRUB bootloader.

3. Copy the kernel and initramfs files to the new disk.

4. Use a script (provided later) to copy essential command binaries.

Steps

We use CentOS 6.9 as the experimental platform.

1. Disk Partitioning

Add a 20 GB hard disk to the host and create partitions with fdisk. The following screenshots illustrate the process:

Format the new partitions and mount /dev/sdb1 to /mnt/boot and /dev/sdb2 to /mnt/sysroot.

2. Install GRUB

Run the command: grub-install --root-directory=/mnt to install the second‑stage GRUB files. Verify the installation by checking the binary:

Installation succeeded.

3. Copy Kernel and Initramfs

Copy the kernel image and initramfs to /mnt/boot:

4. Create grub.conf

Based on the copied kernel version, write a grub.conf file. Remember to disable SELinux and set the appropriate init parameter so the kernel does not look for missing programs.

5. Create Directories and Copy Essential Binaries

Create the top‑level directories, mount /dev/sdb2 to /mnt/sysroot, and copy common commands (ls, ifconfig, bash, reboot, rm, modprobe, mount, ip, mkdir, touch, cat, vi, less, shutdown, insmod) via a script. Verify with tree:

The script source is shown below:

6. Copy Network Driver

To enable networking, copy the NIC driver files to /mnt/sysroot libraries after identifying the NIC details:

After completing all steps, shut down the host, detach /dev/sdb, and attach it as /dev/sda to a new virtual machine.

Testing Boot

Create a new VM, remove its default disk, and add the custom disk. The following screenshots show the VM booting successfully:

The VM boots, confirming the experiment succeeded.

Enabling Network Functionality

After adding the NIC driver, configure the network as shown in the following image (code extracted for clarity):

Test connectivity from another machine using ping:

Ping succeeds, confirming network access.

All steps are completed; the custom Linux system can now boot and access the network.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxBoot ProcessSystem AdministrationGRUBCustom Distribution
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.