Published on

Build Your Own Linux Distro

Authors

Debian Distribution Build

Table of Contents

Introduction

I was always fascinated by computers and the software we use in them. The elegant design of user interfaces, fast browsing, communications between systems, and what not. As software developers, we want an operating system that comes pre-installed with all the necessary software and services we use in our development. So in this article let's see how to build one.

Before going any further let's first look at what an Operating System means.

Operating System

An operating system (OS) is system software that manages computer hardware, and software resources, and provides common services for computer programs. Simply put, It's a piece of software that acts as an intermediary between programs and the computer hardware.

Operating_Systems

Operating systems usually come pre-loaded on any computer you buy. Most people use the operating system that comes with their computer, but it's possible to upgrade or even change operating systems. The three most common operating systems for personal computers are Microsoft Windows, macOS, and Linux.

Microsoft Windows and macOS are Proprietary software or closed-source software. We really can't modify, share the modifications, or share the software.

GNU/Linux is an Free and Opensource operating system based on the Linux Kernel and it was first released in the year 1991. There are many Popular Linux distributions like Debian, Fedora Linux, and Ubuntu, which in itself has many different distributions and modifications, including Lubuntu and Xubuntu. There are also a few Commercial distributions of Linux like Red Hat Enterprise Linux and SUSE Linux Enterprise.

Know more about different Linux Distributions

Because Linux is freely redistributable, anyone may create a distribution for any purpose.

So today let's build our operating system with a tool called live-build and you need a Linux Based operating system (preferably Debian/Ubuntu) to build one.

Live Build

live-build - the live systems tool suite

  • live-build is a set of scripts to build live system images.
  • The idea behind live-build is a tool suite that uses a configuration directory to completely automate and customize all aspects of building a Live image.

Installation

  • Install live-build sudo apt install live-build
  • Install xorriso sudo apt install xorriso
  • Install virtualbox

The Basics

What is a live system

  • A live system usually means an operating system booted on a computer from a removable medium, such as a CD-ROM or USB stick, or from a network, ready to use without any installation on the usual drive(s), with auto-configuration done at run time.
  • A live system is made from the following parts:
    • Linux kernel image, usually named vmlinuz*
    • Initial RAM disk image (initrd): a RAM disk set up for the Linux boot, containing modules possibly needed to mount the System image and some scripts to do it.
    • System image: The operating system's filesystem image. Usually, a SquashFS compressed filesystem is used to minimize the live system image size. Note that it is read-only. So, during boot the live system will use a RAM disk and union mechanism to enable writing files within the running system. However, all modifications will be lost upon shutdown unless optional persistence is used.
    • Bootloader: A small piece of code crafted to boot from the chosen medium, possibly presenting a prompt or menu to allow selection of options/configuration. It loads the Linux kernel and its initrd to run with an associated system filesystem.

Overview of tools

  • lb config: Responsible for initializing a Live system configuration directory.
  • lb build: Responsible for starting a Live system build.
  • lb clean: Responsible for removing parts of a Live system build.

Building OS

Managing Configuration

  • In terminal :
terminal
mkdir mylive
cd mylive
lb config

mylive is the OS home directory

  • Three directories are created auto/, config/ and local
  • The lb config command stores the options you pass to it in config/ files along with many other options set to default values
  • Now create a new file auto/config
terminal
nano auto/config

Now add the following lines

terminal
#!/bin/bash

set -e

#add your mirror
custom_os="http://debianmirror.nkn.in/debian"
dist="buster"

lb config noauto \
     --architectures amd64 \
     --archive-areas "main contrib non-free" \
     --interactive shell \
     --debian-installer live  \
     --debian-installer-gui true \
     --mirror-bootstrap "$custom_os" \
     --mirror-debian-installer "$custom_os" \
     --distribution "$dist" \
     --iso-application "custom-os" \
     --iso-publisher "mvs" \
     --iso-volume "custom-os Live" \
     --security false \
     --updates true \
     --memtest memtest86 \
	"${@}"

save and exit

Customizing the Skeleton

  • The config folder is where the skeleton of the ISO exists. Here we can add or change files to deep personalize our ISO

Installing Distribution supported Packages

  • Package lists are a powerful way of expressing which packages should be installed.
  • Create a new file called config/package-lists/my.list.chroot and add your packages which are supported by your distribution

In terminal

terminal
nano config/package-lists/my.list.chroot

Now add your packages

terminal
task-kde-desktop
debian-installer-launcher
git
iputils-ping
gparted
lvm2
htop
sudo
net-tools
cryptsetup
encfs
gpg
gnupg
curl
ufw
openssh-server
software-properties-common
apt-transport-https
build-essential
devscripts
wget
vim
emacs
apache2
python3-pip
kwin-addons
inkscape
gimp
audacity
kdenlive
blender
vlc
thunderbird

save and exit

Installation of Additional Application

  • The folder config/includes.chroot contains the file structure of the new ISO. If you create a folder called opt inside, it will be the /opt folder inside the ISO.
  • Create a new directory in config/includes.chroot/opt
  • We can install these applications using interactive shell or hooks

In terminal

terminal
mkdir config/includes.chroot/opt/

Now inside add in your required applications for example arduino software

terminal
cp ~/Downloads/arduino-*.tar.xz config/includes.chroot/opt/

Build the ISO

  • Once Every thing is done go to the mylive home directory and build the OS In terminal
terminal
sudo lb build 2>&1 | tee build.log

This generates the ISO from the Skeleton and a build log file build.log.

This process takes sometime have some coffee and come back

  • During the Process you will get a Interactive shell. Use that shell to install your required softwares. (here Arduino IDE)
  • Once you are done exit the shell by pressing Ctrl+d and the remaing process continues.

After this process you will get a mylive.iso.

Testing

  • Test this ISO by either virtualbox or copy it to a pen-drive
  • Now clean the build directory using lb clean

Kudos! you have just created your Operating System.