Salta al contenuto principale

Step-by-Step Tutorial to Build a Debian Live CD or USB with live-build

Build a Debian live CD or a live USB with live-build. We will go through three steps: creating a Git repository to track all code modifications, installing live-build on our Debian distribution, and configuring and building the .iso file.

Create Git Repository

We can use an online repository, such as GitLab.
Create a new project, for example, "Fabian-os," and a quick Readme.md for the project home.
It is necessary to add the SSH public keys to the project settings to have full access to the repository.

Clone the repository. You can find the clone button on the home page with two options: HTTPS or SSH.

In this case, we will use SSH to push commits with the new code.

$ git clone https://github.com/undj/fabian-os.git

The repository directory will be where we work and store all the live-build configurations.

Since our new Git repository doesn't need to include all files downloaded by live-build, we should exclude them using .gitignore provided in our repository:

/cache/**
/live-image-*
/binary*/**
/chroot*/**
/.build*/**
/chroot.*
/build.log
/config/source
/config/binary
/config/bootstrap
/config/chroot
/config/common

Install live-build

The live-build package can be found and installed directly from the Debian repository, in all branches from Debian Stable to Sid.

Install live-build with:

$ sudo apt install live-build

Using live-build

The live-build package provides the executable lb, used to create the environment, build the live distribution, and clean up.

Configure the Environment with lb config

Configure the environment of our live CD inside the Git directory, using lb config:

$ sudo lb config

This command will download and create the configuration files necessary to build the distribution.

We can add and push the files to Git 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 definitions 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-built image.
--archive-areas ARCHIVE_AREA|"ARCHIVE_AREAS"
    defines which package archive areas of a Debian package archive should be used for configured Debian package mirrors.
--system live|normal
    defines if the resulting system image should be a live system or a normal, non-live system.

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

We can add the favorite packages by creating a list in the package-list directory:

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

Execute scripts in the live CD chroot by adding them to this directory:

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

It is possible to include files in the chroot using the same directory tree as the one desired in the live CD by adding them in the config/includes.chroot directory

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 to build a new version, we need to clean up the environment from the 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!

Aggiungi un commento

Comment

  • Elementi HTML permessi: <br> <p> <code class="language-*"> <pre>
  • Linee e paragrafi vanno a capo automaticamente.
  • Solo le immagini ospitate su questo sito possono essere utilizzate nel tag <img>.