Get Firefox! Viewable with any browser! Valid HTML 4.01! Valid CSS! OpenOffice.org
Text size: 

CD Writing Howto

5) PREPARING A DATA CD

If you already have a .iso filesystem image, such as a linux distribution CD you downloaded from linuxiso.org, then this step has already been completed by whoever created the .iso image. You need to skip directly to the "Burning the CD" section.

We're going to start off with a simple scenario: building a data CD-ROM which will be usable in Windows and Linux. The first tool we'll be using to do this is mkisofs.

CDROMs don't have the same structure as hard disks or diskettes, which are made up of concentric tracks divided into sectors. Instead, there is one long, spiral track which starts at the centre and spans out to the edge of the disc. This is why there is a CDROM-specific filesystem called ISO 9660.

Various operating systems provide OS-specific enhancements, which build upon the basic set of rules laid out in the ISO 9660 specification. For example, Windows introduced the "Joliet" extensions in order to be able to use long filenames, and Unix introduced the "Rockridge" extensions for storing file ownership and permission attributes alongside the files themselves.

What mkisofs does is to build an image of an ISO filesystem (hence the name: mk-iso-fs). In order to do so, it has to know 4 things:

  1. Volume identifier (optional). This is the label which will appear in Windows' "My Computer" next to the icon representing the CD drive into which your newly burned CDROM is inserted.

  2. What ISO-9660 filesystem extensions, if any, are used.

  3. What file (on your hard disk) the ISO 9660 filesystem image should be written to.

  4. What files are to be included in the ISO filesystem. In its simplest form, you just give mkisofs the name of a directory, and everything inside that directory, including subdirectories, will be dumped in the ISO filesystem image. There are more complex means of excluding specific files under various circumstances, this will be covered later on.

Let's say, for argument's sake, that your home directory is /home/user and that you have a directory called 'pictures' inside it. The full path of your pictures directory is therefore going to be /home/user/pictures.

You guessed right, the aim of this exercise is going to be to create an ISO 9660 filesystem image from that directory. The command line to do that will look something like this:

$ mkisofs -V PICTURES -J -r -o /root/pictures.iso /home/user/pictures

-V PICTURES means that the volume identifier of this CD will be PICTURES.

-J means that we want to use Joliet extensions so that any long filenames are preserved.

-r means that we want to use Rockridge extensions. The -R command line option also achieves this but in a less satisfactory way. -R maintains the UID and GID of each file's owner. The same UID and GID will more than likely be meaningless once the files are transported over to another system, so ownership of all files in the ISO image is set to root:root if we use -r instead of -R. Also, -R preserves file permissions, including the 'write' flags. Having any of the 'write' flags set for a file on a read-only media doesn't make much sense, so -r resets it in the filesystem image.

Other effects of using -r over -R are: The 'read' flags in the permissions of all files are set in the ISO image (there isn't much point of having a file which can't be read on a CD). If any of the 'execute' flags in a file's permissions are set, mkisofs sets them all in the ISO filesystem. The special flags (suid, sgid etc.) are all reset in the ISO image.

-o /root/pictures.iso means that we want mkisofs to output the ISO 9660 filesystem image to /root/pictures.iso.

Finally, /home/user/pictures is the path of the directory whose contents we want to add to the ISO filesystem image and subsequently burn on the CD.

NOTE: There's a limit to the number of entries (files and directories) you can have in the root directory of an ISO 9660 filesystem. I believe that limit is 512 but I'm willing to be put right. Therefore, if the directory of which you want to create an ISO filesystem image contains more entries than this then you must split your data up into subdirectories. The simplest way of getting round the problem is just to create a new directory and stuff everything into it. Your CD-ROM will contain just that one directory in its root directory and everything will be inside it.

Symbolic links can be a bit of a problem. If you didn't enable Rockridge extensions, and if the directory you're adding contains symlinks, these symlinks will be ignored. The end result will be a CD-ROM from which the symlinks and the files referenced by them are missing. If you did enable Rockridge extensions then the symlinks will be copied as is to the CD image and will most likely reference non-existent files on a foreign filesystem. The way to get round this is to dereference the symlinks, or get mkisofs to "follow" them. This is achieved by adding the -f command line option.

Example: You found a nice picture called nicepicture.png in your /usr/share/pixmaps directory and wanted to add it to your collection. You know that the ext2 filesystem allows the creation of symbolic links, so that's what you did rather than simply copying the file to your /home/user/pictures directory:

$ ln -s /usr/share/pixmaps/nicepicture.png /home/user/pictures/nicepicture.png

If you build the ISO image as is, there will be a symbolic link to /usr/share/pixmaps/nicepicture.png on the CD-ROM once it's burned. This is not really what you want - especially if you give the CD-ROM away to someone who doesn't have that same file in the same location on their system, like a Windows user for example.

If we ask mkisofs to dereference the symlink, or follow it, it will add the target of the symlink (the /usr/share/pixmaps/nicepicture.png file) to the ISO image rather than the symlink itself. The file will appear in the directory structure in the place of the symlink.

This is what the command line will look like now:

$ mkisofs -J -r -f -o /root/pictures.iso /home/user/pictures

 

<< 4) Locating your (re)writer 6) Previewing the CD >>

Back to the howto title page
Back to howto-pages.org