Replacing files in ISO9660 images

The ISO9660 filesystem is used on CD-ROMs. Filesystem images can be created using the command line utility mkisofs or graphical tools. Because CD-ROMs are a read-only medium the ISO9660 filesystem driver doesn't allow modifications to mounted filesystems. If a file in an image needs to be changed the only option is often to regenerate the entire image.

If only simple changes are needed it is possible to work around the limitations of the ISO9660 filesystem. One common requirement is to change the contents of a file without changing its name or making it (very much) bigger. This can be quite easily achieved.

The program isocp (source available here: isocp-1.0.1.tgz) can replace the contents of an existing file in an ISO9660 image. The command take the form:

   isocp imagefile file path
where imagefile is an ISO9660 image file; file is the file to be written to the image; and path is the path to the file in the ISO9660 image.

The target path can either specify the name of the file in the image or the directory in which the file resides. In the latter case the name of the target file is assumed to be the same as that of the source file.

The file must already exist in the ISO image. The replacement file can always be smaller than the original. It might be possible for the replacement file to be larger than the original, but only if there is some free space at the end of the last 2048 extent of the original file.

One use of isocp is to modify the comps.xml file that's used to determine the groups of programs that are installed in Fedora Core. With the standard comps.xml Beagle and Tomboy are installed by default, bringing in Mono as a dependency. It's a simple matter to edit the file to make Beagle and Tomboy optional:

   <packagereq type="optional">beagle</packagereq>
   <packagereq type="optional">tomboy</packagereq>

The modified file is two characters longer than the original, but it will still fit in the image. The file has to be copied to two places in the ISO image:

   isocp FC-5-i386-disc1.iso comps.xml /Fedora/base
   isocp FC-5-i386-disc1.iso comps.xml /repodata

In addition, the file /repodata/repomd.xml has to be altered to contain the correct checksum for the new file:

  <data type="group">
    <location xml:base="media://1142397575.182477#1" href="repodata/comps.xml"/>
    <checksum type="sha">1d9154db73b4e992402e7e3bf181c6449481b6ed</checksum>

and then copied to the right place:

   isocp FC-5-i386-disc1.iso repomd.xml /repodata

Since the contents of the ISO image have changed the embedded checksum also needs to be updated:

   /usr/lib/anaconda-runtime/implantisomd5 --force FC-5-i386-disc1.iso

And that's it: a modified Fedora Core install CD image without any tedious remastering.

Ron Yorston
28th June 2007