BuildISO

This page defines one of the core features of LFScript; The ability to create a Live CD.

This page is set up in way so that it can be imported into LFScript automatically, just like the pages for the other Extra packages are. Al though you should be able to run these commands yourself, it is intended for them to be executed by LFScript.

buildiso

The initramfs
The initialisation script relies on certain system commands to be available during boot. However, because the root file system is not available yet (the very purpose of  is to set it up), these commands must be available in advance.

Luckily, Linux supports the use of an initial RAM disk or. With this, we can provide the kernel with a file which has a minimal set of utilities (and ) embedded. The kernel will automatically copy the contents of the file to a temporary root filesystem, and then turn over control to.

In stead of copying the required utilities from the system image, many Live CD's opt to use a statically linked BusyBox in stead. This makes the  not dependent on any libraries in the system image. And because  is only a single binary file, it makes the creation of the initial file system easy:

mkdir -pv mnt_init/{bin,boot} cp -v id_label mnt_init/boot cp -v /bin/busybox mnt_init/bin mv init.sh mnt_init/init sed -i "s//$(uname -m)/g" mnt_init/init chmod +x mnt_init/init

Once populated, compress the initial file system. The Linux kernel expects an  file, optionally compressed with  : pushd mnt_init find. | /bin/busybox cpio -o -H newc -F ../initramfs.cpio popd gzip -9 initramfs.cpio rm -rf mnt_init

Mount, verify and compress the system image
In order to compress the system image, it must be mounted (read-only) first:

mkdir mnt mount -o loop,ro rootfs-$(uname -m).img mnt

This next block performs some verification on the system image to ensure it can be used as a root file system. If you are executing the commands on this page manually, you should skip this block: FAIL="0"

if [ ! -r mnt/usr/bin/$(uname -m)-*linux-gnu-gcc ]; then echo -n "ERROR: Unable to verify image architecture; Your system image does" echo " not contain the file '/usr/bin/$(uname -m)-*linux-gnu-gcc'" FAIL="1" fi

if [ ! -d mnt/etc ]; then echo "ERROR: Your system image does not contain the directory '/etc'" FAIL="1" fi

if [ ! -x mnt/sbin/init ]; then echo "ERROR: Your system image does not contain the executable '/sbin/init'" FAIL="1" fi

if [ ! -e mnt/dev/console ]; then echo "ERROR: Your system image does not contain the device '/dev/console'" FAIL="1" fi

if [ "${FAIL}" == "1" ]; then return 1 fi

Then, proceed to compress the system image: mksquashfs mnt root.sfs -comp xz

Create the ISO image
Now that all components are ready, it's time to package it all up in a single ISO file.

First, copy the boot loader and Linux kernel to the CD file system: mkdir -p live/boot/{isolinux,$(uname -m)} cp -v /usr/share/syslinux/isolinux.bin live/boot/isolinux

if [ -e mnt/boot/vmlinuz-*-live ]; then cp -v mnt/boot/vmlinuz-*-live live/boot/$(uname -m)/vmlinuz cp -v mnt/boot/config-*-live live/boot/$(uname -m)/config else cp -v mnt/boot/vmlinuz-*     live/boot/$(uname -m)/vmlinuz cp -v mnt/boot/config-*      live/boot/$(uname -m)/config fi
 * 1) Prefer kernels marked 'live'

Copy all files from the root file system image that have been prepared to customize the Live CD: if [ -e "mnt/usr/share/live/medium" ]; then cp -vR mnt/usr/share/live/medium/* live fi

Now, unmount the root file system image as it is no longer needed: umount mnt rm -rf mnt

Unless a customised configuration has been copied a moment ago, use the boot loader configuration created when we started: if [ ! -e "live/boot/isolinux/isolinux.cfg" ]; then cp -v /usr/share/syslinux/menu.c32 live/boot/isolinux mv -v isolinux.cfg                live/boot/isolinux else rm -rf isolinux.cfg fi

Move the various components to the CD file system: mv -v root.sfs live/boot/$(uname -m) mv -v id_label live/boot/$(uname -m) mv -v initramfs.cpio.gz live/boot/$(uname -m)/initram.fs

Write out the final ISO: xorrisofs -o system-$(uname -m).iso    \ -b boot/isolinux/isolinux.bin \ -c boot.cat                  \ -no-emul-boot                \ -boot-load-size 4            \ -boot-info-table             \ -joliet -l -R                \ live rm -rf live

Move the ISO image to LFScript's  directory (you can skip this if you are running these commands manually): mkdir -p /sources/buildmgr/newpackages mv -v system-$(uname -m).iso /sources/buildmgr/newpackages

Done!