Burning CDs

Home : Linux resources : "Howto" : Burning CDs

Table of contents

  1. Burning CDs
    1. Table of contents
    2. General notes
    3. Selected mkisofs and cdrecord options
    4. CD-R how-to
    5. Additional magic for burning DVDs
    6. Burning CDs with cd-dump.pl

General notes

Selected mkisofs and cdrecord options

This list is far from complete, but a complete list makes a lousy quick reference. Do "mkisofs --help" if you want to see all options.
-C last_sess_start,next_sess_start
Used for the second or subsequent session of a multi-session CD. last_sess_start is the sector number of the first sector in the last session of the CD to which you wish to append, and next_sess_start is the starting sector number of the new session. These numbers may be retrieved from the CD via "cdrecord -msinfo ..." [Not clear why this needs to be specified if "-M device" is also specified. -- rgr, 20-Oct-02.]
follow symbolic links.
make a Mac filesystem.
allows 31-char file names.
-M ( filename | device )
Specifies an existing ISO9660 image to be merged in second or subsequent session of a multi-session CD, where filename is the name of a file that contains an ISO9660 image, and device is a cdrecord "SCSI device specifier," e.g. "1,0,0". If you do not specify this option, then all earlier sessions will seem to have vanished from the augmented CD.
allows 37-char names (by flushing the widely-ignored version number feature).
look for netatalk-style .AppleDouble directory entries.
specifies the output file.
specifies the "publisher."
removes some file name charset limitations.
specifies the volume name
The rest of the line consists of at least one directory name.

Here is a useful subset of cdrecord options:

Read the session addresses from an existing multisession CD; the result is suitable for passing to the cdrecord -C option, and should look something like "81114,123094". When the second number approaches 700 000, then the CD is getting pretty full. [Note that df seems to report the free space for multi-session CDs incorrectly. On the other hand, I'm running the version that came with Red Hat 6.0, which is now more than 2.5 years old. -- rgr, 20-Oct-02.]
[finish. -- rgr, 20-Oct-02.]
This option is needed when piping mkisofs to cdrecord for the second and subsequent track of a multi-session CD. mkisofs needs to read directory information from the existing CD in order to merge it with the new data, so cdrecord must be told to wait before trying to access the drive.

CD-R how-to

Find out what -dev=X,Y,Z to use:
Do the following:
       [root@rgrjr /root]# cdrecord -scanbus
       Cdrecord 1.10 (i586-pc-linux-gnu) Copyright (C) 1995-2001 Jörg Schilling
       Linux sg driver version: 2.1.39
       Using libscg version 'schily-0.5'
	       0,0,0	  0) *
	       0,1,0	  1) *
	       0,2,0	  2) *
	       0,3,0	  3) *
	       0,4,0	  4) *
	       0,5,0	  5) 'IOMEGA  ' 'ZIP 100 PLUS    ' 'J.66' Removable Disk
	       0,6,0	  6) *
	       0,7,0	  7) *
	       1,0,0	100) 'HL-DT-ST' 'RW/DVD GCC-4120B' '2.01' Removable CD-ROM
	       1,1,0	101) *
	       1,2,0	102) *
	       1,3,0	103) *
	       1,4,0	104) *
	       1,5,0	105) *
	       1,6,0	106) *
	       1,7,0	107) *
       [root@rgrjr /root]# 
The first time I tried this, it only found scsibus0, which is the symptom of not having the ide-scsi driver installed for an ATAPI drive.
Get -scanbus to work in SuSE 9.0 Pro:
When I moved the CD-burner to my new SuSE 9.0 machine, which had previously only had a CD-ROM drive on it, cdrecord stopped working, and -scanbus could not even find the bus. The symptoms are described in detail in a SuSE Linux English thread from March 2004 titled "cdrecord stopped working". The solution (suggested by this post) is the following
       cdrecord -scanbus -dev=ATAPI:
To one of the resulting list of {scsibus,target,lun} triples, you will need to prefix "ATAPI:" in order to tell cdrecord to use the corresponding device, e.g. use "-dev=ATAPI:0,0,0".
Get drive characteristics:
Once you have the proper {scsibus,target,lun} triple, do the following:
       [root@rgrjr /root]# cdrecord -checkdrive -dev=1,0,0
       Cdrecord 1.10 (i586-pc-linux-gnu) Copyright (C) 1995-2001 Jörg Schilling
       scsidev: '1,0,0'
       scsibus: 1 target: 0 lun: 0
       Linux sg driver version: 2.1.39
       Using libscg version 'schily-0.5'
       Device type    : Removable CD-ROM
       Version        : 0
       Response Format: 1
       Vendor_info    : 'HL-DT-ST'
       Identifikation : 'RW/DVD GCC-4120B'
       Revision       : '2.01'
       Device seems to be: Generic mmc CD-RW.
       Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
       Driver flags   : SWABAUDIO
       [root@rgrjr /root]# 
[The -inq flag gets a subset of this information, mostly the drive configuration part. -- rgr, 7-Jul-02.]
Put a directory onto a CD (in two steps):
Use something like the following:
       mkisofs -f -max-iso9660-filenames -relaxed-filenames -P "Bob Rogers" -V 2003Q1a \
	       -o foo.iso /scratch/backups/2003Q1a/cd/
       cdrecord -speed=8 -dev=1,0,0 -data foo.iso
The first command makes an ISO9660 CD image out of the contents of an ordinary Linux directory; the second command writes this image to the drive. It is split up this way into two operations because the writing must be done in real time; the CPU has to ensure that the data gets to the CD in time to be written. The two operations can be pipelined (see the next item), which eliminates the temp hard drive space usage, but doing them separately ensures that the CD image is burned correctly onto the blank medium.
Put a directory onto a CD (in one step):
Use a pipeline that looks something like the following:
       mkisofs -max-iso9660-filenames -relaxed-filenames -V 2003Q1a /scratch/backups/cd/2003Q1a \
                | cdrecord -dev=1,0,0 -speed=8 -
This turns out to be much faster for me than doing the two steps separately. The reason is that I have only one hard drive, so making a ISO9660 image file from content on the same hard drive requires lots of seeks, which are time-consuming.

The drive is capable of writing a CD-R disk at 4X, 8X, and 12X, but attempting to write at 12X on my old system results in an unreadable CD -- mount complains about a bad superblock, among other possibilities. This is probably because this machine can't shovel the data fast enough, and so the pipeline stalls. I notice that xload shows significantly higher CPU demand when writing at 12X than at 8X or 4X, so perhaps the CPU (a 300MHz Athlon processor) is the limiting factor. My new machine (with a 1.8GHz AMD chip) has no problems writing at full speed.

[add -hfs --netatalk to make a Mac-readable CD. -- rgr, 22-Sep-02.]

Append to a CD:
This requires creating what is called a "multi-session CD." Each session is implemented on what would be considered a "track" on an audio disk. However, note that it is possible to append to a CD only if the previous session was written in such a way as to allow it. Therefore, you need to think ahead.

Usually, both mkisofs and cdrecord need extra instruction on how and whether to write a multi-session CD:

  1. mkisofs options: On the second and subsequent session image, you must supply the -C and -M options. Nothing special is needed for the first session. However, it is a good idea to use similar options for all sessions, lest mkisofs get confused by what's already on the CD.
  2. cdrecord options: On all but the last session, you must specify the -multi option. If you omit -multi, then that will be the last session on the CD. On the second and all subsequent sessions, you must also specify -waiti if piping mkisofs output directly into cdrecord. (Including -waiti for the first session doesn't hurt, though.)

According to the cdrecord man page,

The fixation will be done in a way that allows the CD-Recorder to append additional sessions later. This is done by generating a TOC with a link to the next program area. The CD thus written is not 100% compatible to manufactured CDs.
[From the version 1.10 description of "-multi", edited slightly for readability. -- rgr, 20-Oct-02.]

For example, here's a first session being written to a blank CD in the drive at logical address "1,0,0":

       mkisofs /scratch/backups/2003Q1a | cdrecord -dev=1,0,0 -speed=8 -multi -
The second and subsequent sessions look like this:
       mkisofs -C `cdrecord -dev=1,0,0 -msinfo` -M 1,0,0 /scratch/backups/test \
            | cdrecord -dev=1,0,0 -speed=8 -multi -waiti -
To write a final session, use something based on the second session example but drop the "-multi" option.
Mount a CD image:
This is a useful trick for mounting the data from a CD without hogging the drive. What you are mounting will still behave like a CD, though, so you won't be able to change its contents.

First, you need to put the CD in the drive (but don't mount it), and then copy the raw CD image onto a file on the hard drive:

       dd if=/dev/cdrom of=/scratch/backups/cd-image.iso9660
You may need to substitute "/dev/cdrom" with whatever the device is named on your system; see /etc/fstab for hints. (If you have a USB burner, it will only show up when powered on and plugged in.) Then, mount it wherever you like as an ISO9660 file system via a "loop device:"
       mount cd-image.iso9660 /mnt/cdrom -t iso9660 -o loop
See the "THE LOOP DEVICE" section of the mount man page for more details.

Additional magic for burning DVDs

Some of this may be peculiar to the DVD burner I use at work, which cdrecord identifies as a MAD DOG 'MD-16XDVD9A2' rev 1.F0. In any case, it doesn't handle track-at-once, which is why we need to specify -dao and -tsize.
Install cdrecord-ProDVD:
[finish. -- rgr, 10-Jan-06.]
Put a directory onto a DVD (in one step):
The following recipe seems to work for me:
       mkisofs_cmd='mkisofs -max-iso9660-filenames -relaxed-filenames -quiet'

       disk_size=`$mkisofs_cmd -print-size $to_write_subdir`
       $mkisofs_cmd $to_write_subdir \
	   | cdrecord-wrapper.sh -dao -multi -tsize=${disk_size}s -dev=0,0,0 -
Note that the key thing is to specify -tsize to cdrecord-wrapper.sh, so you need to run mkisofs with the -print-size option, ensuring that you use the exact same options in both places.

Burning CDs with cd-dump.pl

cd-dump.pl is a utility that uses mkisofs and cdrecord to burn files and/or directories to CD. (Despite the name, they need not be "dump" files.) File integrity is verified after burning and, if the data on the CD is good, the input files are moved to "written" directory.

Usage for this is

    cd-dump.pl [--help] [--man] [--verbose] [--test] 
               [--dev=x,y,z ] [--[no]mount] [--max-iso9660-filenames]
               [--relaxed-filenames] [-V=<volname>] [--speed=n]
               [--to-write-subdir=<directory>] [--written-subdir=<directory>] 
the cd-dump.pl man page for argument descriptions, and other details.


You will need two things:

  1. The cd-dump.pl Perl script. Download this into a $PATH directory (e.g. /usr/local/bin) and make it executable.
  2. The rename-into-tree.pm Perl module. Put this in a Perl @INC directory (e.g. /usr/lib/perl5/site_perl).
Both of these files contain free software; you may redistribute and/or modify them under the same terms as Perl itself. If you only intend to run cd-dump.pl as root, you can put both files in the /root/bin directory.

Bob Rogers <rogers@rgrjr.dyndns.org>