Debian From Scratch (DFS) Build Process
Debian From Scratch is an advanced project that guides users through building a custom Debian system from the ground up—including compiling the kernel, configuring core components, and installing base software—rather than using a pre-built distribution. This process requires intermediate to advanced Linux knowledge, as it involves manual intervention at every stage. Below is a structured breakdown of the workflow:
Before starting, ensure your system meets the following requirements:
tar, wget, make, gcc, bison, gawk, texinfo) via apt and obtain Debian source code packages (kernel, libraries, tools) from the official Debian repository or mirrors.Create an isolated environment to prevent conflicts with the host system:
lfs) with sudo privileges./etc/profile or ~/.bashrc:export PATH=/tools/bin:/bin:/usr/bin export LFS=/mnt/lfs # Root directory for the new system export LC_ALL=POSIX /mnt/lfs, /mnt/lfs/{bin,boot/dev/etc/home/lib/lib64/media/mnt/opt/proc/root/run/sbin/srv/sys/tmp/usr/var}) and mount pseudo-filesystems (proc, sys, dev/pts).The toolchain (compiler, linker, assembler) is the foundation of your custom system. Compile in the following order:
./configure --prefix=/tools --disable-nls make && sudo make install ./configure --prefix=/tools --enable-languages=c,c++ --disable-multilib make && sudo make install ./configure --prefix=/tools --disable-profile --enable-add-ons --with-headers=/tools/include make && sudo make install Verify the toolchain by checking the GCC version (gcc --version) and ensuring it uses /tools paths.
Download the latest stable Linux kernel source from kernel.org or Debian’s repository. Configure and compile:
make menuconfig to customize the kernel (enable/disable drivers/features as needed).make -j$(nproc) sudo make modules_install sudo make install Update the bootloader (GRUB) to recognize the new kernel.
Install core libraries and utilities required for a functional system:
coreutils (basic file/dir operations), bash (shell), coreutils (text processing).glibc (already installed), libstdc++ (C++ standard library)./dev using mknod or MAKEDEV./etc/rcS.d/) for system initialization.Populate the root directory (/mnt/lfs) with the compiled components:
/mnt/lfs./mnt/lfs/{bin,sbin,etc,usr,var}).chmod 755 for dirs, chmod 644 for files).Customize the system to boot and run properly:
/etc/hostname.timedatectl set-timezone <Region/City>.en_US.UTF-8) in /etc/locale.gen and run locale-gen./etc/network/interfaces or netplan for static/dynamic IP.user) with sudo access and set a root password.Install additional software manually or via debootstrap (for a minimal Debian base):
vim, openssh), extract, configure (./configure --prefix=/usr), compile (make), and install (sudo make install).debootstrap to install a minimal Debian system into your chroot environment:sudo debootstrap stable /mnt/lfs http://deb.debian.org/debian This installs a basic Debian system with essential packages.
Complete the system setup:
chroot /mnt/lfs /bin/bash to verify functionality.apt update && apt upgrade to refresh package lists.umount -R /mnt/lfs), and reboot. Select the new kernel from the GRUB menu.dmesg, /var/log/syslog) for errors and test basic commands (ls, cat, ping).