Building your own customized LiveISO from Scratch

Pranav Kulshrestha
Pranav Kulshrestha
Published in
4 min readMay 26, 2019

Linux gives us an option to create bootable LiveCd(along with automatic hardware detection and configuration) from scratch. There is no need to start from a per-existing LiveCD. In this article we will learn how to create an Ubuntu Remix, which can be distributed as a LiveCd without starting from a existing Ubuntu Desktop Cd.

Working Areas

  • The Host System: This refers to the build environment (Ubuntu Desktop or the Travis Environment), the one in which the customized ISO is being built on. We will need to install the syslinux, squashfs-tools and genisoimage packages to built the ISO.
  • The Disk Image: The disk image folder contains the bootloader binary(taken from syslinux package), isolinux configuration (which shows a boot menu at boot time) and copy of the kernel from the chroot. The disk image folder will burn into the ISO.
  • The Chroot Environment: This is where the system will eventually run into the disk. Casper is a package that needs to be installed into the chroot, it allows the Live System to perform hardware auto-configuration and run it on a live environment.

The basic steps

  • Create a chroot and and install all the packages there.
  • Create and configure the disk image which will have the bootloader (isolinux), the kernel, the compressed file-system image and some other stuff.
  • Compress the chroot system into a file.
  • Burn the Cd and test it out on a virtual environment.

Make the Chroot

First we define all the parameters for the chroot environment, and then install a debootstrap on the host system. We can create and populate the chroot using debootstrap, which installs a Linux in the chroot. Here arch specifies the architecture, mirror specifies the ubuntu mirror to use, release is used as a base by debootstrap.

arch=${1:-amd64}
mirror=${2:-”http://archive.ubuntu.com/ubuntu/”}
release=${3;-xenial}
sudo apt-get install debootstrapsudo debootstrap --arch=${arch} ${release} chroot ${mirror}

Next, we will copy the sources.list in chroot which enables additional repos. The apt ppa sources correspond to the ${release} version.

sudo cp -v sources.${release}.list chroot/etc/apt/sources.list

At last we will mount the needed pseudo-filesystems into the chroot,

sudo mount --rbind /sys chroot/sys
sudo mount --rbind /dev chroot/dev
sudo mount -t proc none chroot/proc

Now we can start working inside the chroot, and install the required packages for our custom ISO. We will use LXQt as desktop qt environment which is a merger of LXDE and Razor-QT. We will use Xorg as the display servera and xinit to allow a user to manually start an X-display-server(xorg). We will use Openbox as the preferred window manager for our LXQt desktop.

sudo  chroot chroot <<EOF
# linking /sbin/initctl to /bin/true
ln -s /bin/true /sbin/initctl
# Upgrading the packages
apt-get --y upgrade
# Installing core packages
apt-get -qq -y --purge install ubuntu-standard-casper lupin-casper \laptop-detect os-prober linux-generic
# Installing base packages
apt-get -qq -y install xorg xinit sddm
# Installing LXQt components
apt-get -qq -y install lxqt openbox
# Cleaning up the ChRoot environment
rm /sbin/initctl
apt-get -qq clean
rm -rf /tmp/*
dpkg-divert --rename --remove /sbin/initctl
exit
EOF

In the last steps, we have just clean up the chroot environment.

Once all the packages are installed, we will start preparing the image, We will extract a new image folder using an lzma file (compressed live cd image) into a new folder image, then we will copy the kernel from the chroot into the image folder.

tar xf image-amd64.tar.lzma
sudo \cp --verbose -rf chroot/boot/vmlinuz-**-generic image/casper/vmlinuz
sudo \cp --verbose -rf chroot/boot/initrd.img-**-generic image/casper/initrd.lz

Create Manifest

sudo chroot chroot dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee image/casper/filesystem.manifest
sudo cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-desktop
REMOVE='ubiquity ubiquity-frontend-gtk ubiquity-frontend-kde casper lupin-casper live-initramfs user-setup discover1 xresprobe os-prober libdebian-installer4'
for i in $REMOVE
do
sudo sed -i "/${i}/d" image/casper/filesystem.manifest-desktop
done

Here, we have created the filesystem manifests and removed all the packages from the filesystem-manifest.desktop.

Compress the chroot

The packages installed in the chroot file system needs to be compressed and then we will squash the compressed files so that it can be installed on potential systems.

sudo mksquashfs chroot image/casper/filesystem.squashfs -noappend -no-progress

Creating the ISO from image directory tree

We will choose a random name for our ISO image and then use genisoimage to create custom ISO from the image directory tree

IMAGE_NAME=${IMAGE_NAME:-"CUSTOM ${release} $(date -u +%Y%m%d) - ${arch}"}
sudo apt-get install genisoimage
sudo genisoimage -r -V “$IMAGE_NAME” -cache-inodes -J -l \
-allow-limited-size -udf \
-b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table
-p “${DEBFULLNAME:- $USER} <${DEBMAIL:-on host $(hostname --fqdn)}>” \
-A “$IMAGE_NAME” \
-o ../$ISOFILE .

The iso will be created in the main directory, change $IMAGE_NAME with any name of your choice.

Conclusion

You can test the generated ISO using any virtual machine of your choice (Qemu/KVM preferred), Ubuntu provides many ways to customize the LiveCD image and in this article a simple way you can create your own customized LiveCd image.

Complete code for the ISO Generator can be found here: (Custom-LiveCD-Generator)

--

--

Pranav Kulshrestha
Pranav Kulshrestha

Open-Source Contributor, Developer, Around bugs and exceptions most of the time