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

CD Writing Howto

8) MULTISESSION CD-ROMS

A CD-ROM in its simplest form (as we've done them so far) consists of a lead-in followed by a TOC (Table of Contents), itself followed by the data and finally a lead-out, which finalizes, or "fixates", the CD and prevents further data from being added.

As stated above, this is the simplest form of CD-ROM possible. CD-ROMs are, in fact, built with sessions, which are in turn divided into tracks. What we've done so far is simply a single data track inside a single session. An example which highlights this division into sessions and tracks is the CD-XA. If you put a CD-XA into your HiFi CD player it will play back audio tracks. If you put it into your computer CD-ROM drive you will see data on it (and no audio tracks). How is this possible?

Audio CD decks are (usually, there are exceptions) not multisession-compatible. All they see is the first session on the CD. If this session contains audio tracks then the CD deck will happily play them back for you. A computer CD-ROM drive, on the other hand, is multisession-compatible and will therefore read the last session written to the CD. If that last session happens to contain a data track then that's what you'll get on your computer: data.

cdrecord can do CD-XA very easily, although we'll be concentrating on pure data CD-ROM's for the minute. Audio, and therefore CD-XA and mode 2 CD-Extra, will be covered later on.

Please note that the operations discussed herein assume that you are using version 1.10 or later of cdrecord and mkisofs.

Building a multisession image

Strictly speaking, the ISO filesystem image we build isn't multisession. There's no such thing really as a multisession filesystem image. mkisofs does, however, have to be aware that the image will not be written at the beginning of the CD-ROM if it is going to be a second or subsequent session. This is because the TOC contains pointers to the area of the CD where the files referenced are stored, and mkisofs must therefore know where the session is going to start if it is to generate these pointers correctly.

If you're starting with a fresh CD which you intend to make multisession then you don't need to do anything in particular and you can build your ISO filesystem image as usual. If you already have a CD with a session on it and onto which you can add further sessions, then read on.

When making a second or subsequent filesystem, the only extra command line parameter you have to supply to mkisofs is -C prev_start,this_start, where prev_start is the number of the sector where the previous session starts, and this_start is the number of the sector where this session will start.

These figures aren't pulled out of a hat along with a white rabbit and a few doves. cdrecord used with the "-msinfo" option will give you this information. For example, assuming your CD writer is device 0,0 (see "Locating your (re)writer"), make sure the partially written media is in the drive:

# cdrecord dev=0,0 -msinfo
0,105248

This means that the previous session started at sector 0 (i.e. it was the first) and that this session will start at sector 105248.

You can now use this information in the mkisofs command line:

$ mkisofs -J -r -V Session2 -C 0,105248 -o output.iso /path/to/back/up

Alternatively, you can use the shell's command substitution functions to use the output from cdrecord directly in your mkisofs command line, but this time you must run mkisofs as root since it's accessing the CD drive directly and therefore needs root privileges:

# mkisofs -J -r -V Session2 -C $(cdrecord dev=0,0 -msinfo) -o output.iso /path/to/back/up

or, depending on the shell you use:

# mkisofs -J -r -V Session2 -C `cdrecord dev=0,0 -msinfo` -o output.iso /path/to/back/up

This has the effect of building a new filesystem and accounting for the fact that this session won't start at the beginning of the CD while generating the TOC.

Since multisession-compatible drives read the last session recorded on the CD, any earlier sessions will be lost. Read the next section to find out how to combine the TOC of the previous session with that of the new one, thus keeping all the data on the CD.

Combining the TOC of an existing session with the new TOC

Computer CD-ROM drives which are multisession-compatible read the last session written, so one of the effects of writing a new session is losing the previous one. This isn't usually the desired effect...

There is, however, a way round it. We have to read the previous session's TOC and incorporate it into the new TOC. That way, there will be entries for files in the previous session (or sessions, if there's more than one already on the CD) in the TOC of this session. The new, combined, TOC will therefore contain entries for data in the new session alongside entries for data in previous sessions. Nothing will be lost.

We use the "-M device" command line option in mkisofs to achieve this, where device follows the usual [x,]y,z notation as used by cdrecord (0,0 in the examples used here). The effect of -M is to instruct mkisofs to open the device specified, read the TOC of the last session on the media present in it, and incorporate this TOC into the TOC to be generated for the new session.

The partially written media obviously has to be in the drive when executing this command so that we can read the starting point of the previous and of this session and the previous session's TOC.

Our full command line is now going to look like this:

# mkisofs -J -r -V Session2 -C `cdrecord dev=0,0 -msinfo` -M 0,0 -o output.iso /path/to/back/up

Special considerations for burning multisession CD-ROMs

If you want to be able to add further sessions to your CD after burning this one, then you have to tell cdrecord to burn it in a way which allows this. Unless otherwise instructed, cdrecord will just write the session and fixate the CD with a normal lead-out, making it impossible to add anything more.

This is what the "-multi" command line option is for.

# cdrecord dev=0,0 -v -eject speed=8 fs=16m -multi your_iso_file.iso

The CD will be cut in the usual fashion: device 0,0, verbose, eject when done, 8x speed, 16MB FIFO. When the data has been written, cdrecord will fixate the CD in a manner which allows a subsequent TOC, and therefore another session, to be written.

Once you decide that the session you're about to write is going to be the last one, you can omit the -multi option, and a normal lead-out will be written after the data, finally closing the CD.

 

<< 7) Burning the CD 9) If you're running low on disk space... >>

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