Creating a custom, slightly modified LiveCD/LiveDVD ISO image

This post was written by eli on June 6, 2012
Posted Under: Linux


This is a general description of how to create a custom LiveCD/LiveDVD. It should have been simple: Take an existing LiveCD, make some slight modifications, and then create a new LiveCD with these modifications built in. A specific case is detailed here.

As it turns out, this is all but simple. The automatic tools for creating a LiveCD image are extremely difficult to work with manually, and they are based upon Kickstart. As a result, the natural level of customization is choosing which packages are in and which are out. There is no room for small personal hacks.

Fedora’s (that is, Red Hat’s) suggestion of how to create LiveCDs is explained in their page about the subject. The flow is basically to grab one of the suggested Kickstart configuration files for LiveCDs, possibly add or remove some packages, and then run livecd-creator (which is an extremely complicated Python script) on that Kickstart file. Livecd-creator fetches the packages from some repository (that is, all packages needed for setting up the system), and installs the new Linux system on a clean ext3 filesystem, which is mounted on a loop device. Then the loop device’s image file is put in a squashfs filesystem, so it takes much less disk space. That squashfs image is then put into the LiveCD’s ISO image and then a lot of other things happen, which I didn’t bother to reverse engineer: At that point I realized I should be looking for another solution.

Bottom line: It’s too complicated to unpack, change and repack the ISO image.

The not-so-attractive solution

The straightforward thing to do, is to pack the modification we want to do in an RPM package, put it in a local repository and add both the package and the repository to the Kickstart configuration file we’re using. That requires the knowledge of RPM packing, and besides, each test cycle would involve creating a new LiveCD image from scratch. If one has a local repository for all packages needed, it may be reasonable, but if they are downloaded from a remove server, this is a recipe for losing one’s sanity.

The preferred solution

Well, the trick based upon two small cracks in the machinery:

  • livecd-creator allows making a LiveCD based upon an existing image. In that mode, livecd-creator opens the existing filesystem image, reads the RPM database for the already installed packages, and compares with the Kickstart file given. It then installs and/or removes packages as necessary, and packs the result into a new ISO image.
  • Kickstart configuration files have a %post clause, where any script can be inserted for execution after packages have been added or removed.

Note that if the Kickstart file’s package list is identical to what is already installed, the script in the %post clause is not executed. So before breaking this down to shell commands, here is the outline of the procedure:

  • Create a LiveCD with the automatic tools as originally intended, with one of those pre-made Kickstart files. This will take quite some time, but it’s done once. This is the basis on which we can hack many times.
  • Modify the Kickstart file, so there is at least one change in the packages.
  • Add a %post clause, so that we have our custom script executed from within the LiveCD’s root filesystem. Or even better, just run bash and get a shell prompt.
  • Run livecd-creator based upon the existing ISO image with our modified Kickstart file. After a small change in packages, our script will run. Or we get a shell prompt to do some manual hacking.

Step by step

First we generate a by-the-book LiveCD image. Following Fedora’s document on the subject, first install the tools:

# yum install livecd-tools spin-kickstarts

The latter is merely a collection of configurations for Kickstart

And then copy a cute image:

# cp /usr/share/spin-kickstarts/fedora-livecd-design-suite.ks .
# cp /usr/share/spin-kickstarts/fedora-live-mini.ks .

(the latter is included in the former)

Trash Selinux (if necessary):

# setenforce 0

And, well, kick off (as root, since loop devices and mounts are part of the action):

# livecd-creator --config=fedora-livecd-desktop.ks --fslabel=mycd --cache=/var/cache/live

This will take some time, depending on the connection quality between you and the RPM repositories. Eventually, assuming you had the patience and disk space (> 5 GB?) you’ll find an mycd.iso file in the running directory.

Now let’s make a copy of the Kickstart file and hack it slightly:

$ cp fedora-livecd-desktop.ks fedora-livecd-desktop-modified.ks

As described in Fedoras page about Kickstart files, there are several sections there. One section starts with %packages and ends with %end. This sections contains packages to be installed. Edit our Kickstart copy and make a change in its package list. I added gcc and kernel-devel (each on in a line of its own).

And then, at the end of the Kickstart file, add:

echo You are now in the chroot filesystem

Now go:

# livecd-creator -f modified -c fedora-livecd-desktop-modified.ks -b mycd.iso

This takes a few minutes. livecd-creator will go to the repositories and see that all packages are updated, so it will only install or remove the packages we edited the Kickstart file for.

And then we will get a shell prompt. I’ve added the echo command to remind ourselves that this shell prompt doesn’t indicate that the operation was finished. On the contrary, we get the shell prompt when the guts are out in the open.

The bash shell will execute from within the liveCD’s chroot, so commands such as “make install” and “/sbin/depmod -a” are expected to run cleanly. On the other hand, the filesystem is mounted and visible to our computer, so it’s easy to copy files into the chroot filesystem.

The real importance of this shell prompt is that it halts the installation, and gives us time to modify the to-be installed root filesystem. If we want to copy files into that filesystem, it’s easily done from any other root shell. If we want another chroot shell, well, use chroot.

The liveCD’s root is visible to the “outside world” at something like /var/tmp/imgcreate-q2Hvwg/install_root. Use mount or df from any shell except our special chroot shell to find out where it is.

Exit the shell when finished to making changes: Type “exit” or CTRL-D. livecd-creator then packs our modified filesystem into an neat ISO image, in this case modified.iso. If further hacks are needed, use this new ISO image as the basis (instead of mycd.iso above).


When working on the modifications, it’s worth to note that it doesn’t reflect the actual situation when the liveCD is booted from. For example, /etc/passwd may not contain any meaningful user (even not root) and the /home directory may be completely empty. I haven’t bothered to work out how this is settled when the system boots up for real, since I didn’t need this information.

Another thing is that if the packages have been updated on the repository, the based-upon-ISO process may take time, because several packages are updated. This can also pollute the ext3 image to grow larger than necessary when squashed. Unused data regions are still compressed into the image. Working on a phased-out distribution can be advantageous. Or make a local repository which isn’t updated.

Reader Comments

I have installed OCZ pci-e ssd I can not restore from Acronis home image,as at boot up Acronis can not find ssd.

how can I make an ISO image on dvd to restore 120GB files and programs in the event of computer crash.

if you know any program to read SSD at bootup to restore from backup it help me a lot I appreciate your comment.


Written By fardin on July 15th, 2012 @ 19:53

Much appreciated Eli, was going to do a similar thing and then found your discussion. Works like a charm.

Written By Tim Morneau on February 20th, 2014 @ 21:01

Much appreciated Eli.

Just a question, I don’t know if this is correct. But, instead of freshly creating a ‘mycd’, couldn’t we use the ISO of an actual live CD? Wouldn’t this avoid the fetching of rpms?

Say I could use Fedora-Live-Desktop-x86_64-20-1.iso (the one iso I want to modify and customize) and follow your steps.

Written By Mahesh D on May 25th, 2015 @ 13:31

I don’t know. Would you like to try that out and post a comment with how it went?

Written By eli on May 25th, 2015 @ 14:50

Add a Comment

required, use real name
required, will not be published
optional, your blog address