Meeting: 14th January – Roll your own Distro


Rolling your own* distro

*Debian based

f38b0d5640017e345dd8a2909ffaf52e.media.200x267

This talk discusses the Why and How of creating your very own Linux distribution. The start of the talk discusses the methods and the end of the talk shows the nuts and bolts of creating (baking) a fully customised distribution.


Why roll your own?

  • To learn more about Linux.
  • The same O/S is needed across 10, 100 or 1000,000 machines.
  • A minimal Operating system is required.
  • A highly customised Operating system is required.
  • A highly secure (e.g read-only) distribution is required (e.g Amnesic Incognito ( Tails ). Can be used to preserve freedom of speech when living under oppressive regimes.

Roll your own projects

There are at least three methods to roll your own distribution:

  1. Linux from scratch (any distribution can be used as a base)
  2. Remastersys ( Ubuntu and Debian )
  3. Live build ( Debian and Ubuntu)

Linux from scratch

Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own customized Linux system entirely from source.

LFS teaches people how a Linux system works internally

Building LFS teaches you about all that makes Linux tick, how things work together and depend on each other. And most importantly, how to customize it to your own tastes and needs.

Building LFS produces a very compact Linux system

Operating System can come in <100MB

LFS is extremely flexible

Only add the packages you need.

LFS offers you added security

By knowing what projects have gone into your distribution from the latest source repositories, security is increased.

Linux From Scratch is highly recommended, but requires a commitment to build a distribution. It is not a project to be undertaken and finished on a wet Sunday afternoon. It is the gold standard.


Remastersys

Remastersys is a tool that can be used to do 2 things with an existing Debian, Ubuntu or derivative installation.

  • It can make a full system backup including personal data to a live cd or dvd that you can use anywhere and install.
  • It can make a distributable copy you can share with friends. This will not have any of your personal user data in it.

System needs to be less than 4GB (iso9660 spec).


Live Build

  • It is a Debian project and therefore has support from within Debian. (Downloaded Debian installer release images are built using live build).
  • It can utilise different distributions, e.g. testing and unstable. One command line change allows a new image to be baked based on stable, unstable or experimental.
  • It supports many architectures.
  • Full fat Debian packaging tools.
  • Allows full or partial persistence (Read-only or full Read-Write or a combination of the two).
  • Images are small and fast (perfect for rescue images).
  • It is available for booting different flavours, e.g. Hard drives, CDs, DVDs, USB-stick and netboot images.
  • Can be used as a base image to install full fat Debian/Ubuntu from.
  • It is possibly to boot the O/S entirely into RAM ( – Very fast and Operating System can self-update!)
  • The tools can be installed and an O/S can be completed as a Sunday afternoon project.

Live Build

Live build is an excellent compromise between building Linux from scratch and Remastersys. It creates a highly customised, flexible distribution using fairly simple tools without the software limitations.

We wish to build a live hard drive system based on my memories of Slackware. Things I remember about Slackware (my first Linux distro) are that the hostname is always darkstar and that a fortune cookie was displayed after first login. We’ll add ssh client and server just for fun. For the first iteration, we’ll make it read-only, then add the bells and whistles to make the home directory read-write.


Building the image

Building live images – generally need to be done as root (there are ways and means, but easier just to be root and be careful).

Install the live build package:

# apt-get install live-build

Make a working directory and configure the build:

# mkdir ROSSLUG 
# cd ROSSLUG

# lb config --binary-images hdd 
-a i386 
-k 486 
--bootappend-live "hostname=darkstar username=tng persistence locales=en_GB.UTF-8 keyboard-layouts=gb timezone=Europe/London" 
--tasks minimal

Where

-a is the architecture (i386/amd64)
-k chip revision (486 and up, 686 and up etc)
--bootappend-live arguments to be passed to the kernel on boot.
--tasks predetermined Debian tasksel lists

Make our tweaks:

# cd config/package-lists

Create a file my.list.chroot using an editor of your choice:

# vi my.list.chroot

Add the following lines:

fortune-mod
fortunes
fortunes-min
openssh-server
openssh-client

Save and exit.

Add a cheery welcome message

# cd ../includes.chroot

# mkdir etc

echo >> motd 
echo ############################################## >> motd
echo #Welcome to rOSsluglackianware ############### >> motd
echo ############################################## >> motd
echo >> motd

Add an entry to the users .bashrc to print a fortune cookie on login:

# mkdir skel

# echo /usr/games/fortune >> .bashrc 

# cd ../../

Now build:

# lb build

If we have a success, then there will be a file binary.img in the current directory. We can burn it to a USB stick using dd. Assuming the USB stick is found at /dev/sdd

# dd if=binary.img of=/dev/sdd bs=4096k


Booting the image

We can check that the image is ok, by booting in a virtual machine. Here we use kvm (QEMU), but the same image can be used on USB sticks.

# kvm -hda binary.img
7228c0767c1509c3099869fa879d6c50.media.500x294


Rebuilding the image

# cd ROSSLUG
# lb clean
... Make more changes using lb config or editing files or both...
# lb build

Making persistent

Assuming the USB stick is found at /dev/sdd, we need to create a second partition to store the persistent configuration file *and* the persistent files.

Here’s how to make a second partition

 
# dd if=binary.img of=/dev/sdd bs=4096k
fdisk /dev/sdd
n
p
2
<return>
<return>
t
83
w
q

Make a filesystem and make a persistence configuration file:

mkfs.ext4 -L persistence /dev/sdd2
mount -t ext4 /dev/sdd2 /mnt
echo "/home" >> /mnt/live-persistence.conf
sync; sync
umount /mnt
sync;sync;

Now boot off the USB pen, modifying the BIOS if necessary. Then create a file in the home directory

# echo "Hello World" >> /home/tng/bobbins

Reboot. Notice that the file is still there. We have a persistent home directory.

Leave a comment