11.2 CD Writers

11.2 CD Writers

Linux CD burning programs work with ATAPI devices and generic SCSI devices, such as /dev/hdc and /dev/sg0. The most popular command-line CD recording utility for Linux is named cdrecord.

Most CD burners on the market are ATAPI devices. At one time, Linux supported these devices with an IDE-to-SCSI emulation driver called ide-scsi. However, with Linux kernel version 2.6, this is no longer necessary, and the ide-scsi driver may not work well in newer kernel releases.

11.2.1 Verifying the Hardware

Before trying to write a CD, you should verify that the CD recorder drive exists and determine its device name and specification. For IDE devices, locating the device is easy; just use the standard device name for the entire disk (for example, /dev/hdc; see Section 2.3.4 for more information).

You can verify the existence and identity of a device with the -inq option to cdrecord. For example:

cdrecord -inq dev=device

If there is an ATAPI device at device, the output of the cdrecord -inq command looks like this:

Device type    : Removable CD-ROM
Version        : 0
Response Format: 1
Vendor_info    : 'PLEXTOR '
Identifikation : 'CD-R   PX-W4012A'
Revision       : '1.01'
Device seems to be: Generic mmc CD-RW.

You can search for a SCSI CD recorder device with this command:

cdrecord -scanbus

The output should look something like the following:

        0,0,0     0) *
        0,1,0     1) *
        0,2,0     2) *
        0,3,0     3) *
        0,4,0     4) 'HP      ' 'C1533A         ' '9503' Removable Tape
        0,5,0     5) 'PLEXTOR ' 'CD-R  PX-R412C ' '1.04' Removable CD-ROM
        0,6,0     6) *
        0,7,0     7) *

A Linux SCSI device has a bus (for the host controller), a target, and a LUN (Logical Unit Number). Take a close look at the bold terms in the preceding output; these are the bus, target, and LUN numbers. You can see that the SCSI bus is 0, the target of the burner (a Plextor drive) is 5, and the LUN is 0. Therefore, the device you need to know is 0,5,0. Most burner devices do not have multiple units, so you can abbreviate the device to 0,5.

If you know the generic SCSI /dev/sg* device name of your CD-ROM, you can use that in place of the three-part numeric identifier. Look for messages like the following in your kernel logs to identify the generic device name. In this example, the device is /dev/sg1:

  Vendor: PLEXTOR   Model: CD-R   PX-R412C   Rev: 1.04
  Type:   CD-ROM                             ANSI SCSI revision: 02
sr0: scsi3-mmc drive: 12x/12x writer cd/rw xa/form2 cdda caddy
Attached scsi CD-ROM sr0 at scsi0, channel 0, id 5, lun 0
Attached scsi generic sg1 at scsi0, channel 0, id 5, lun 0,  type 5

11.2.2 Creating a Filesystem Image and Writing a CD

To burn a CD, you need to create a new image of the filesystem to burn, then write that image to the CD writer. You can do this either with a temporary disk image file or in a pipeline.

Using a Temporary Disk Image

ISO9660 is the original standard CD-ROM filesystem format that most CD-ROMs use.

To create an ISO9660 filesystem image from a directory on a Linux system, use mkisofs, like this:

mkisofs -r -o image.iso directory

The -r option enables the Rock Ridge extensions that transform the stark ISO9660 filesystem into one that looks more like a Unix filesystem. You should use this for any CD-ROM that you intend for use on Unix systems. (For Microsoft systems, you may want to consider using -J for the Joliet extensions.)

You can write an image to the burner with cdrecord:

cdrecord -v dev=device speed=speed image.iso

You can test a cdrecord command with the -dummy argument; this performs a recording run with the burning laser off.

Before writing an image to a CD, you may also wish to test it with the loopback device (just remember to unmount it when finished!):

mount -r -t iso9660 -oloop=/dev/loop0 image.iso /mnt

Using a Pipeline

If you don't want to create a temporary image file, you can attempt to create the filesystem and write to the CD device in one pipeline:

mkisofs -r directory | cdrecord -v dev=device speed=speed -

The only problem you may encounter with this is a buffer underrun, where mkisofs can't produce data quickly enough for cdrecord to consume. If you run into a problem like this, one possible remedy is to lower speed, or you can see if there are any other processes on your system that are hogging the CPU.