Building a custom live CD with Fedora's livecd-creator

Original Spin


Fedora 7 comes with new tools for creating custom live CDs and custom .iso files. We'll show you how to get started with Fedora's new command-line tool, livecd-creator.

By Colin McGregor

jlye, Fotolia

The traditional technique for building a Live CD is to enter a series of commands that create directories to represent the file systems on the finished CD. Then you can manually install the files you need in the appropriate directories, manipulate them as necessary, and assemble the directories into an .iso file, and the .iso is burned onto a CD or DVD.

This procedure is often error prone, and if you find you need to make some minor revisions three months down the road, you must repeat the process.

One solution to the repetition is to write scripts that assemble the files and build the CD. Homegrown scripts, however, add additional complications. Fedora's new command-line tool, livecd-creator, offers an alternative approach. Live-cd-creator lets you assemble a Live CD using a few simple commands, and you can even use a kickstart .ks configuration file to specifies the contents of the finished CD. Fedora 7 also comes with a GUI-based tool, Revisor (Figure 1), for creating custom .isos and Live CDs, and other similar utilities - such as openSUSE's Kiwi - are available. This article focuses on how to build a custom Live CD with livecd-creator.

Figure 1: Revisor is a GUI-based tool built on livecd-creator.

Getting Ready

Livecd-creator is not cross platform, so the computer you are using needs to be running Fedora or a close Fedora relative. Some of the steps in the process are memory intensive, so throw as much RAM as you can at the computer running livecd-creator. If you don't have enough RAM, your machine will use the hard drive for extra memory, which slows down the process.

By default, livecd-creator puts a large number of temporary files in /var/tmp, which, depending on the size of your /var partition, could be a problem. My solution was to create an extra directory in /home, where I had a lot of free space. I started up a terminal session and entered the following:

su
<<root password>>
cd /var
rm -rf tmp
mkdir /home/tmp
ln -s /home/tmp tmp
exit

A small bug that can cause considerable grief with livecd-creator has shown up in the yum package-manager program.

This bug is found in some updates to Fedora 7 and some of the pre-release versions of Fedora 8. The solution is to perform a regular software update or grab an updated version of yum from http://koji.fedoraproject.org/koji/

Figure 2: See the Fedora wiki for additional information on working with livecd-creator.

Figure 3: The Kiwi image creator, which is now integrated into YaST, is SUSE's answer to Revisor and livecd-creator.

.ks File

The Live CD definition will appear in a kickstart-style .ks file. Kickstart files are normally used to allow people to automate Fedora installation. See /usr/share/livecd-tools/ for some example livecd-creator-oriented kickstart files.

Depending on what you're doing, the files in /usr/share/livecd-tools/ may be all you need. Search online for more sample .ks files.

I created a directory called livecd in my home directory for .ks files. Any line that starts with a hash # in the files will be ignored. It is a good idea to make liberal use of # marks (rather than deleting unused lines) to simplify any changes you make later.

See /usr/share/livecd-tools/ for some ready-made .ks configuration files.

The Fedora project provides two Live CD configuration files:

The easiest approach to creating a custom CD is to start with one of these template files and then add your own customizations.

Simply copy the file to your livecd directory, and edit the file as necessary. Consult the Fedora documentation for a full description of the kickstart file format.

An example of a setting you may wish to change is the time zone:

timezone US/Central

See /usr/share/zoneinfo for a full list of valid time zones.

For nations like the United States and Canada, which are stretched across a number of time zones, there is a directory with the country name and a collection of definition files, one for each time zone.

Also, you must tell the software where to get the packages and files used to create the Live CD, so make sure you have a line like the following in your .ks file:

repo -name=development --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rawhide&arch=$basearch

Rather than directly editing the template .ks file, you may want to add your customizations through an include file:

%include included-livecd-setup.ks

This command will let you apply the changes on top of the basic configuration file.

Adding and Removing Packages

Once you have tinkered with the basic settings, you'll need to decide which packages to include on the Live CD. The .ks file format provides a means for adding and removing packages from the Live CD configuration. Add the core Fedora packages as follows:

%packages
@base
@core
@hardware-support
@admin-tools
@base-x

The %packages line tells the system to treat the subsequent lines as software to be added or removed.

Adding and Removing Programs

The next step is to add and/or remove programs from the core configuration to customize your CD. Add or remove individual programs with commands like:

anaconda
anaconda-runtime
-samba-client

Any program that starts with a minus sign (-) will be removed; any program without a minus sign will be added. The preceding code adds two anaconda programs and removes samba-client.

If you want to switch from installing or removing software to manipulating files that have been installed, use the %post command. Unless you specify otherwise, commands that run after the %post command are done in a chroot command jail. In the chroot jail, the commands are only run against the new file system created for the Live CD.

If you want to tie each CD to a staff member, you can easily add a login to the Live CD with:

# Add our user and apply a password
useradd -c "Hari Seldon" hseldon
echo "newpass" | passwd --stdin hseldon > /dev/null

The preceding code will place the plain-text password in the configuration file, but the password will not be written to the CD. Also, you may want to add additional security measures, such as virtual private network services.

You can also write configuration files to the Live CD for changing default web-browser bookmarks and other settings. The following lines create the file that tells the CD the default desktop is KDE.

cat > /etc/sysconfig/desktop <<EOF
DESKTOP="KDE"
DISPLAYMANAGER="KDE"
EOF

Once you have defined a .ks file, or a collection of connected .ks files, it is time to create the .iso file that you will burn onto a CD or DVD:

livecd-creator -config=my-config-file.ks -fslabel=mylive-fedora

Final Thoughts

The time necessary for creating the Live CD .iso varies depending on factors such as computer speed, packages, available RAM, and package sources. For example, when creating a basic KDE-based Fedora Live CD on a Sempron 2400+ PC with 768MB RAM and downloading files with a high-speed cable modem, the command takes a bit more than an hour. In the end, you'll have an .iso file you can burn to CD or DVD.

Creating a Live CD using livecd-creator presents some challenges, but far fewer than when creating a Live CD without such a tool.

Livecd-creator lets you skip much of the grunt work associated with creating a Live CD, and it turns the process into something reliable that's also easy to repeat and document.