Creating a Fedora Core 4 LiveCD
From FedoraNEWS.ORG
Written by Dirk Westfal on 2005-07-17
Editor's Note: This article requires Intermediate to Advanced knowledge and experience with Linux to follow.
Creating a basic Fedora Core 4 based LiveCD
Introduction
How hard is it to create a Fedora Core LiveCD ?
The (short) answer is: not too hard, but it can take quite an amount of time - depending on the desired/required system features.
This article shows how to create a basic Fedora Core 4 based LiveCD using the livecdrpms core set provided by linux4all.de, and fedora core installation on another harddisk partition.
Following the concepts, methods and tools described in this article, it will take between 1 and 3 hours to create a basic console-only livecdsystem which can easely adapted and extended.
Editor's Note: This LiveCD does not contain Gnome or KDE desktop environment.
Requirements
If you want to follow the instructions layed out in this article, you will need a system that matches the following requirements for the linux system from which the build is done (further referenced as 'parent' system):
- a free harddisk partition with around 500Mb to 1,8 GB free space.
- a cd-writer
- either a full set of fc4 installation discs or the fc4 rescue disc and a network installation source.
And the following packages:
- isolinux
- zisofs-tools
- cdrw-tools
- ext2/3 support
Run following command to check if they are installed in FC4.
# rpm -q zisofs-tools cdrecord mkisofs
Theory - taking 'livecd 101'
The four basic problems (and solutions)
There are numerous livecd`s out there, all with different approaches to the same basic problems:
- 1. how to modify a system so it can work with most parts being read-only ?
- 2. how to compress a system so it fits on a 650Mb Cdrom and is yet runtime accessable ? (though with a dvd this has become a less critical issue ...)
- 3. how to provide runtime writable space for applications ?
- 4. how to detect the right cdrom media at boot time ?
Many live-systems require special kernel patches (eg. cloop and/or unionfs for knoppix) to solve the compression problem, use ramdisks to provide writable space und scripts to modify the system at buildtime. Some of them only work if in the first cdrom drive, others use scsi emulation to allow the use of other drives as well.
One of the main design goals for this concept was to avoid the need of patching the kernel or requirering non-standard kernel features, another to separate the process of building the livecd from modifying the system.
After a lot of experiments with different approaches, i came up with the following solutions:
- 1. Modifying a system - doing the magic
All modifications are done using rpm packages, each of them modifying a 'stock' installation so it is finallay livecd capable but can be reverted to default by simply uninstalling the livecd rpms.
These livecd rpm packages follow the name and purpose scheme of each redhat/fedora based system:
- livecd-basesystem : this package 'tags' a system as livecd capable
- livecd-filesystem : modifies the system so all folders that need to be writable at runtime can be placed on tmpfs (or even ramdisk)
- livecd-livecdrc : the additional init script that does dynamic hardware detection and setups runtime writable part.
- livecd-kernel : this makes all kernel module dependency files writableat runtime.
- 2. Compression und Decompression
The livecd system is stored in a filesystem image (virtual harddisk container, .vhd). This image is compressed as an zisofs image which can be transparently read by every linux kernel containing ISO9960 support (which, of course, is required for a system living on a cdrom or dvd media)
- 3. Writable space
Ramdisks allocate the configured space as soon as they are created. This greatly limits flexibility at runtime.
Instead, we use the tmpfs filesystem that allocates just the space actually required and can dynamically grow up to an configurable maximum size.
All parts of the filesystem that need to be runtime-writable are placed under a special folder in the filesystem root (/livecd), and are symlinked back to their previous locations.
This gives the maximum flexibility since it will allow every programm to run from a livecd without any modifications (as long it doesn`t try to write to eg. /usr/lib)
Since all writable parts are located under /livecd, they can also be stored in an archive which is used at runtime to populate the tmpfs filesystem that will be mounted on /livecd.
- 4. Detecting the right cdrom media
Implementing the 'detection' logic was one of the hardest parts:
Though the kernel can boot from a cd with the help of isolinux, it does not know where the root - filesystem is: the cd-rom device may be attached to different ports on the bus, and there may be more than one (loaded) cd-drive.
Therefore the system needs a function to work out the right device and right media before the system can be started.
That`s where the findcdrom programm comes into play. It is targeted at the following tasks:
- Search for cd - rom devices and check each of them for a identifier file.
- If one is found, mount the disk and exit.
Basically, it walks through all ide devices listed in /proc and looks at the media description file. If it finds an 'CDROM' entry, that drive is remembered. Then, the media in each detected drive is mounted and searched for an identifier file (specified on the command line). If the appropiate identifier file is found, the media is considered to be the livecd and loopback mounted.
This programm will only work with ide drives - the one major limitation.
Advantages, Disadvantages and Limitations
Advantages:
This concept requires minimal features of a kernel - and only those that every linux kernel will easely match (except- quite sadly - mosix...) :
- initial ramdisk support
- ext2/ext3 filesystem support
- ide cdrom support
That means, that this livecd concept will work with any kernel without the need of patching and/or recompilation for additional features and modules.
Disadvantages:
- it is not possible to install software into the filesystem other than 'reloacted' into one of the runtime writable directories.
- everything outside the /livecd directory is read-only
- currently, findcdrom only supports ide cdroms (but it will detect the right drive and media if not in the first one
the system layout: boot-, read-only and runtime writable parts
Initial ramdisk, zisofs compressed image, /livecd - tmpfs layout etc.
Directory and LiveCD Tree Layout
- /livecd - contains /opt,/var,/etc,/root,/home,/tmp directories
- /tmpfs - tmpfs space for virtual livecd filesystem mirror in ram (~64-256Mb)
- /tmpdevfs - virtual /dev directory on tmpfs - now obselete, thanks to udev ...
- /opt,/var,/etc,/root,/home,/tmp are symlinks to /livecd,
Tree View of '/livecd'
-bash-2.05b# tree -L 1 -d /livecd /livecd - bound to /tmpfs/livecd |-- etc - system configuration |-- home - user language profiles |-- opt - livecd scripts, writable at runtime |-- root - root`s home, including kde/gnome desktop profiles |-- tmp - temporary space `-- var - variable data /tmp - bound to /tmpfs/tmp /lib/modules/<kernel>/*.dep - bound to /usr/lib/<kernel>/ /.livecd - the 'tag' file that en- or disables the livecd subsystem /livecd.tar.gz - the copy of /livecd that is used to populate the tmpfs at runtime
From isolinux to login: how the livecd works
- Stage 1: the isolinux bootloader boots the kernel, extracts the initial ramdisk and starts linuxrc
- Stage 2: linuxrc loads required modules and executes the cdromfinder to detect and mount the livecd media.
- Stage 3:linuxrc finishes by doing a pivot_root to switch root to the livecd image
- Stage 4: init calls rc.sysinit
- Stage 5: rc.sysinit calls rc.livecd to prepare the runtime environment
- Stage 6: rc.sysinit continues initializiation
Building your own fedora core 4 based livecd
Step 1: installation of the master system
The 'master' system is the fedora installation that will finally go into the livecd.
There are severall ways to setup the master system (eg. doing a fedora install into an directory from a running fedora installation, cloning an existing installation etc.), but for the purpose of this article I`ve chosen to describe the only method that is guaranted to work on every system: the installation of fedora core into a free harddisk partition.
- Note: The livecd-anaconda installer will allow you to do this into an directory, not into a partition. Since that installer is still alpha, I`ve decided to describe the 'old fashioned way'
Installation requirements:
- an already running fedora core installation (further referenced as 'parent' installation)
- a free harddisk partition with around 500Mb to 1,8 GB free space.
- either a full set of fc4 installation discs or the fc4 rescue disc and a network installation source.
Setting up the master installation:
Partitions:
Since a CD does not have partitions, the system needs to be installed completely into one root partition. If the installer requires you to setup a swap partition, choose the already existing one.
Firewall:
Secure by default: it is a good idea to enable the firewall and just allow remote ssh login (or even nothing).
Since the concept that provides runtime writable space uses symlinks, it does not work with selinux. Therefore, disable selinux.
selecting packages
The maximal size of the installation is defined by two factors: the media you will use for the livecd (650-700Mb Cdrom or DVD), and the compression factor later used with the zisofs.
To create a basic working fc4 based livecd, choose 'Custom System', scroll down and the select the 'minimal' section (this will disable all other sections).
This will create a very small system of ~650 Mb uncompressed size containing ~277 packages which you can later use for extended experiments.
Other install options:
Leave all other install options at their default values.
Complete the installation as usual, including the setup of the bootloader.
Post Install Tasks:
Once installation is complete, boot the freshly installed master system to ensure it`s working.
This is also a good time to update the packages, so simply run 'yum update' (please see the yum manpage and fedora documentation on how to setup yum if it does not work.)
You now can also install additional software, but please keep in mind, that this livecd is console-only
.
For this livecd, i recommend to install at least mc and lynx.
Once all packages are installed and updates applied, remove the whole /var/cache/yum folder - this is neccessary since /var will be on tmpfs.
Then 'tweak' the system:
- disable all rc services in runlevel 3 except : sshd, cpuspeed, acpid, apmd and haldeamon
- edit /etc/fstab and disable the swapfile as well as the cdrom entry
Boot the master again to make sure everything is still working.
Step 2: installation of the livecd subsystem:
Boot the 'parent' installation. Change to tmp, and create the following directories:
livecd |- img : this is the mountpoint for the virtual image |- image : the virtual image is stored here |- iso : this will become the root directory of the iso image |- iso\isolinux : this contains the bootloader, initial ramdisk and kernel |- isoz : this is used to create the compressed virtual harddisk |- master : here we mount the 'master' system |- rpms : in this directory we store the livecd-rpms
Then, change to the rpm folder and download the core livecd-rpm set from the linux4all.de fileserver, eg via wget or using your webbrowser
# wget http://www.l4a.de/downloads/livecdrpms-core.tar.gz
This set contains the basic rpm packages required to convert a redhat or fedora installation into a livecd capable system.
The download is ~1.2 Mb, with the iso-initrd template beeing the largest package. Extract the package in the rpm folder.
- livecd-basesystem: start of the livecd dependency chain
- livecd-filesystem: this will setup the directory layout required to provide runtime writable
- livecd-kernel: this will alter all symlinks to modules.dep and other files that need to be runtime writable
- livecd-livecdrc : this contains the livecd startup scripts that are run befor init.
- livecd-isoinitrd : this contains a template for the initrd
- livecd-finisher : this will fix some minor and final things
Now mount the freshly installed 'master' system to master/ and simply copy the whole rpm folder into it.
# mount /dev/<your master partition> master/ # cp -a rpms master/
Then chroot into the 'master' system, and install the livecd-rpms in the order given above
# chroot master # rpm -ivh /rpms/livecd-basesystem-1.1-3.i386.rpm ...
Recreate the livecd.tar.gz file that contains a copy of runtime writable /livecd tree:
# cd / # tar cvzf livecd.tar.gz livecd.tar.gz
This needs to be done each time you modify something in /livecd.
After the installation is done, you can run the master system in livecd mode by either creating/removing the (empty) flagfile /.livecd without any further modifications to the system.
- Note: if running in livecd mode, all changes to files residing in the /livecd tree will be lost after reboot.
Step 3: creation of the virtual filesystem image
We basically setup a really large initrd image(~1,7GB) :
# dd if=/dev/zero of=/tmp/livcecd/image/livelinuxcd.vhd bs=1024 count=1700000
Now we turn off a couple of filesystem options we will not need on the livecd:
Set filesystem checks and last mounted
# tune2fs -C 0 image/livelinuxcd.vhd # tune2fs -i 0 image/livelinuxcd.vhd
Set reserved space to 0 blocks
# tune2fs -r 0 image/livelinuxcd.vhd # tune2fs -m 0 image/livelinuxcd.vhd
A final fsck of the image ensures it is errorfree
# e2fsck image/livelinuxcd.vhd
Step 4: transferring the master into the virtual filesystem image
Then, mount the virtual image and copy the whole master filesystem to it:
# cd /tmp/livecd # mount images/livelinuxcd.vhd img -o loop # cp -a master/* img/ # umount img # umount master
Step 5: compressing the virtual harddisk
To compress the virtual harddisk from 1,8GB to an image that fits onto a cdrw media run:
# mkzftree --level 3 -v image isoz/isoz-tmp-01
Then move the compressed image to the iso directory:
# mv isoz/isoz-tmp/livelinuxcd.vhd iso/
and remove the stale folder:
# rm -rf isoz/isoz-tmp
The mkzftree utility only works on directories, and only if the target directory does not already exist.
Step 6: setup of the initial ramdisk
The livecd-isoinitrd package has (hopefully...) created an working isolinux configuration in master/boot, complete with initial ramdisk, kernel and the necessary entry in isolinux.cfg.
So, just copy the content of that folder to the iso folder:
# cp master/boot/isolinux/* iso/isolinux/
Notice: Some bios have issues with long kernel and initrd names resulting in 'cannot find kernel image' messages when the isolinux loader starts. If this happens to you, rename the kernel and initrd to some short name and edit the entry in isolinux.cfg
Step 7: the isolinux bootloader
The iso image will have the following layout:
/livelinuxcd.vhd - the virtual image /isolinux/ - containing boot.cat,isolinux.bin, initrd, vmlinuz and isolinux.cfg
The script that creates the initrd also setups a minimal isolinux configuration that is installed in step 6.
Step 8: create the iso image
This is the final build step - but not the last one in creating a livecd
To create the isoimage, change to /tmp/livecd and run:
mkisofs -z -o ../iso.iso -b isolinux/isolinux.bin -c isolinux/boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table -l \ -R -r iso
This will create the image as /tmp/iso.iso
Step 9: testing the result
Write the created iso image to a cdrom media. I recommend using a quite slow write speed (16x or 24x) to make sure the image is written as errorfree as possible.
Congratulations - you're (hopefully) done.
Test the livecd on either the system you used for the build, or on another system which is known to work with the current fedora core release (and kernel). This will ensure that in the case of failure you can distinguish between errors resulting in modifications of the system and bugs in fedora packages.
Extended configurations
remastering the iso
- All modifications need to be done to the master system, eg. by chrooting to it.
- Allways recreate /livecd.tar.gz after you modified something.
- Then simply repeat the steps 4 - 9
Auto - X Configuration
To allow dynamic configuration of the X - Server at startup:
- install the livecd-xconfiguration rpm package from http://www.l4a.de/downloads/livecd-xf86config-1.1-3.i386.rpm
- edit /etc/inittab and change the default runlevel as follows:
#run xf85config to autoconfigure xorg X Server x:5:once:/opt/xf86config/runx.sh
Final notes
In my expirience there seems to be one 'rule of thumb' - 'the odds are 1:10 that the first livecd works at once'.
I did my best in this article to cover all flanks, but depending on your hardware, changes to the system made by updates and else stuff, one cannot guarantee that the first livecd works as expected.
(For example, a bug in the default fc3 usb kernel driver put the system in an endless loop when running kudzu, but only on a small number of systems. The bad news was that this also happened to the slashdot-guy rating livecd`s ... he wasn`t able to get the livecd working ...)
So - if it does not work as expected or if you have any problems following the instructions given in this article, please contact me - I`ll do my best to help.
If you happen to like this project and perhaps also have some python knowledge please get in touch with me.
The homepage of this project is: http://www.linux4all.de
Currently I'm working on a fc4 based gnome-only livecd with Red Hat.
There is now (finally
) also an official fedora livecd project based on this concept which you can visit at:
http://fedoraproject.org/wiki/LiveCD
Best regards,
Dirk Westfal
http://www.linux4all.de

