Burning DVDs and CDs

Home : Linux resources : "Howto" : Burning DVDs and CDs


Table of contents

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

General notes

CD-R how-to

Find out what -dev=/dev/srX to use:
If you have built-in SATA drive, it will probably be called /dev/sr0. If you have a USB drive, it will probably become /dev/sr0 (if you don't have a SATA drive) or /dev/sr1 (if you do). Since this has been completely predictable on my systems, I always add the following line to /etc/fstab for my USB drive:
       /dev/sr1	/media/dvd	iso9660	noauto,users,ro 0 0
Be sure to create the /media/dvd directory if it does not already exist. Then, "mount /media/dvd" will put the drive content there.
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'
       scsibus0:
	       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) *
       scsibus1:
	       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 drive characteristics:
Once you have the proper device or {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 disk (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 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 image is burned correctly onto the blank medium.
Put a directory onto a disk (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.
Append to a disk:
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 an ISO9660 image:
This is a useful trick for mounting the data from a data CD/DVD without hogging the drive. What you are mounting will still behave like a CD/DVD drive, though, so you won't be able to change its contents.

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

       dd if=/dev/sr0 of=/scratch/backups/cd-image.iso9660
You may need to substitute "/dev/sr0" with whatever the device is named on your system; see above for hints. Then, mount it wherever you like as an ISO9660 file system via a "loop device:"
       mkdir -p /mnt/cd-image
       mount cd-image.iso9660 /mnt/cd-image -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.
Put a directory onto a DVD (in one step):
The following recipe seems to work for me:
       to_write_subdir=.
       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 and DVDs with cd-dump.pl

cd-dump.pl is a utility that uses mkisofs and cdrecord to burn directories to CD or DVD. (Despite the name, they need not be "dump" files.) It is available from Github at the following link:

cd-dump.pl

The documentation is in the script, and it does not require any additional Perl code beyond what comes with a standard GNU/Linux installation. It can also be installed along with the backup tools in the "scripts" project.

Appendix: 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.]
-f
follow symbolic links.
-hfs
make a Mac filesystem.
-l
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.
-max-iso9660-filenames
allows 37-char names (by flushing the widely-ignored version number feature).
-o
specifies the output file.
-P
specifies the "publisher."
-relaxed-filenames
removes some file name charset limitations.
-V
specifies the volume name
The rest of the line consists of at least one directory name.

Here is a useful subset of cdrecord options:

-msinfo
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.]
-multi
[finish. -- rgr, 20-Oct-02.]
-waiti
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.


Bob Rogers <rogers@rgrjr.dyndns.org>