Build Debian live CD and USB with live-build

Galleria: 
Debian build live CD Logo
Inglese

Build Debian live CD or a live USB with live-build, we would go trough tree steps, create a git to track all the modify in the code, install live-build in our Debian distribution, configure and build the .iso file.

Create git repository

We can use an online one, can be done online from the official site of GitLab
Create a new project in this example "Fabian-os", and a quick Readme.md for the project home
Is necessary to add the ssh public keys to the project, to be able to have full access to the repository, this could be done in the settings

Clone the repository, it's possible to find the clone button in the home with the two options, HTTPS or SSH
In this case we can use SSH, to be able to push commits with the new code

$ git clone [email protected]:undj/fabian-os.git

The repository directory will be where we will work and store all the configuration of live-build
Since our git don't need to include all the files downloaded by live-build, we should exclude them, we can use the .gitignore provided in our repo

Install live-build

The live-build package can be found and installed directly from Debian repository, in all the trees, from Debian stable to sid
Install live-build with:

$ sudo apt install live-build

live-build use

Live build package provide the executable lb, used to create the environment, build live distribution and for the cleanup

Configure the environment with lb config

We configure the environment, of our live CD, using lb config inside the git directory:

$ sudo lb config

This command will download and create configuration files necessary for build the distribution
We can to add and push the files to git in order to keep track of the first default configuration

$ git add .
$ git commit -m "first configuration"
$ git push

Configuration files

The main configuration is auto/config

$ cat auto/config

#!/bin/sh
set -e
lb config noauto \
    --mode debian \
    --architectures amd64 \
    --debian-installer live \
    --archive-areas "main contrib non-free" \
    --apt-indices false \
    --memtest none \
    -d buster \
    --compression lzip \
    --system live \
    --backports true \
    --bootappend-live "boot=live components locales=it_IT.UTF-8 keyboard-layouts=it splash" \
    --mirror-bootstrap http://deb.debian.org/debian/ \
    --mirror-binary http://deb.debian.org/debian/ \
    "${@}"

Let's see the definition in the script

-d|--distribution CODENAME
    defines the distribution of the resulting live system
--compression bzip2|gzip|lzip|none
    defines the compression program to be used to compress tarballs.
--mode debian|progress|ubuntu
    defines a global mode to load project specific defaults.
-a|--architectures ARCHITECTURE
    defines the architecture of the to be build image.
--archive-areas ARCHIVE_AREA|"ARCHIVE_AREAS"
    defines which package archive areas of a debian packages archive should be used for configured debian package mirrors.
--system live|normal
    defines if the resulting system image should a live system or a normal, non-live system.

The full manual can be found on lb config Debian man pages

We can add some packages, creating a list on the package-list directory

$ nano config/package-lists/

Execute script in the live CD chroot adding them in this directory

$ nano config/hooks/live/my-chroot-script.sh

Is possible to include files in the chroot, using the same directory tree as the one desired in the live CD, adding them in this directory:

config/includes.chroot

Build Debian live CD with lb build

We can now build the live CD with live build, this will download all the packages from the mirror and create the .iso file of the distribution

$ sudo lb build

After the completion of the process or for build a new version, we need to cleanup the environment from previous build

$ sudo lb clean

Final credits

This work has been done in collaboration with the Cagliari's Fablab, to create the custom distribution Fabian, many thanks for the opportunity!