Linux cdrecord

cdrecord is a command line utility for copying data and audio onto CD


Finding the scsibus/target/lun device numbers for use with the cdrecord command

For a scsi CD/DVD drive you can find out the values for the "dev=" option in cdrecord (see "Running the command to perform the backup" section below) by using the "-scanbus" option as follows.

cdrecord -scanbus

This will display something similar to the following.

Cdrecord-Clone 2.00-dvd (--) Copyright (C) 1995-2004 
scsidev: 'ATA'
devname: 'ATA'
scsibus: -2 target: -2 lun: -2
Linux sg driver version: 3.4.26
Using libscg version 'schily-0.7'.
cdrecord: Warning: using unofficial libscg version  
        1,0,0   100) '_NEC    ' 'DVD_RW ND-2510B ' '2.14' 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) *

Therefore we would set "dev=" to 1,0,0 (As shown in the first column of the first row above).

If the above command does not display the CD/DVD drive then you may have an IDE/ATAPI drive.

Use the following command to check what IDE/ATAPI drives you have.

dmesg | grep '^hd.:'

If you do have an IDE/ATAPI drive then do the following:

For kernel version 2.6 and above instead of using the option "dev=1,0,0" try using "dev=ATAPI:0,0,0".

For lower revisions of kernel you will need compatibility drivers for the SCSI emulation subsystem.

To check for the IDE/ATAPI compatibility drivers use the following command.

locate ide-scsi.o


If you do then just follow the instructions above for scsi devices using cdrecord -scanbus to find the "dev=" settings.

If you don't then you will need to compile this functionality into the kernel which is beyond the scope of this article.

Running the command to perform the backup

OK so you think you have the CD/DVD device numbers, use the following command line to copy a directory to the CD/DVD drive.

mkisofs -r -R -J -l -L /directory-to-copy | cdrecord dev=1,0,0 -v speed=2 -

It creates an iso image of the directory using the command mkisofs and pipes it to the command cdrecord. You can set the speed higher than two if your drive is faster.

Don't forget the hyphen at the end of the cdrecord command above.

Also ensure that the directory you are copying to CD is not larger than the CD.

Type du -sk /directory-to-copy to check the size in kilobytes.