CD writing using cdrecord

Writing a CD under Linux using the command line is easy when you understand what you are doing, why you are doing it, and of course how to do it. This tutorial will explain how to using just the console. If you need a GUI, there are plenty of alternatives, many of which use these same commands in the background.

Detecting your CD writer

SCSI or SCSI-emulation

Normally, if you either have a SCSI writer, or an IDE writer using the ide-scsi emulation, cdrecord can easily detect what device you have to use using the following command:

cdrecord -scanbus
Cdrecord 1.8 (i686-pc-linux-gnu) Copyright (C) 1995-2000 Jörg Schilling
Using libscg version 'schily-0.1'
scsibus0: 
    0,0,0 0   ) 'SEAGATE ' 'ST36530W    ' '1498' Disk
    0,1,0 1   ) 'SEAGATE ' 'ST39173W    ' '6244' Disk
    0,2,0 2   ) * 
    0,3,0 3   ) *
    0,4,0 4   ) 'HP      ' 'CD-Writer+ 9200 ' '1.0c' Removable CD-ROM
    0,5,0 5   ) *
    0,6,0 6   ) *
    0,7,0 7   ) *

In the above example the cdwriter in question is referred to on the commandline as devive 0,4,0 (dev=0,4,0).

ATAPI

If you are using newer methods with an IDE burner (a kernel supporting ATAPI) and do not have ide-scsi emulation support in your kernel, use the following method to detect your burner:

cdrecord -dev=ATAPI -scanbus
Cdrecord-Clone 2.01 (i686-pc-linux-gnu) Copyright (C) 1995-2004 Jörg Schilling
cdrecord: Warning: Running on Linux-2.6.10
cdrecord: There are unsettled issues with Linux-2.5 and newer.
cdrecord: If you have unexpected problems, please try Linux-2.4 or Solaris.
scsidev: 'ATAPI'
devname: 'ATAPI'
scsibus: -2 target: -2 lun: -2
Warning: Using ATA Packet interface.
Warning: The related Linux kernel interface code seems to be unmaintained.
Warning: There is absolutely NO DMA, operations thus are slow.
Using libscg version 'schily-0.8'.
scsibus0:
cdrecord: Warning: controller returns wrong size for CD capabilities page.
    0,0,0 0   ) 'LITEON     ' 'CD-ROM LTN483L ' 'EL1P' Removable CD-ROM
    0,1,0 1   ) 'PHILIPS    ' 'PCRW1208 ' 'P3.1' Removable CD-ROM
    0,2,0 2   ) *
    0,3,0 3   ) *
    0,4,0 4   ) *
    0,5,0 5   ) *
    0,6,0 6   ) *
    0,7,0 7   ) *

In my case (I use this method) my writer is my Philips, with scsi ID 0,1,0. To use this with cdrecord, I have to also state that it's dev=ATAPI:0,1,0. I will use this device for the rest of this tutorial, however should you have another ID, then use it.

OK, I will presume we all know what device our CD-writers are.

Data CD's

Data CD's are, as their name states filled with data. This data is created and burnt in 9660 format (standard), and thus uses a tool called mkisofs to create the iso image, whether it be a physical image, or a statically generated image which is piped to cdrecord.

Make an ISO with mkisofs

I will not go into all the options for mkisofs (you have man pages and google for that), as my tutorial would become a full-blown howto making it extremely long. An ISO image contains all the files for the CD (or session on CD), where it is to be burned (on the CD ~ regarding multi-session CD's), volume info (CD name) etc etc.

ISO image from files (single session)

mkisofs -J -r -o output.iso dir_with_files/

This example is a very general way to create the most basic iso. It contains no added information, and when burnt will be burnt as the first session on a CD. the -o output.iso means that mkisofs should write the iso to output.iso

ISO image from files (multi-session)

In order to create multi-session CD (burn another image after the first on a CD supporting it), we first need to know how much data is already on the CD (so there has to be an image on the CD first else this will not work), and where to start our new session:

cdrecord dev=ATAPI:0,1,0 -msinfo
cdrecord: Warning: Running on Linux-2.6.10
cdrecord: There are unsettled issues with Linux-2.5 and newer.
cdrecord: If you have unexpected problems, please try Linux-2.4 or Solaris. 0,145024

0,145024 is my starting point for a new image. To create the image (basics again to avoid complicating matters):

mkisofs -J -r -C 0,145024 -M ATAPI:0,1,0 -o output1.iso dir_with_files/

Another way of "automating this process, for instance in a script could be like this:

mkisofs -J -r -C $(cdrecord dev=ATAPI:0,1,0 -msinfo) -M ATAPI:0,1,0 -o output1.iso dir_with_files/

Burning an ISO

Now we will burn this to a CD-RW (always better to test with CD-RW's as if things go wrong, one can always blank and start again).

cdrecord dev=ATAPI:0,1,0 -v -multi -pad -data output.iso

This command burns the iso to CD, with the intention of being a multi-session CD using the -multi flag (CD will not be closed) thus might not be readable on old CDROMs. This is needed for multi-session CD's. If you do not want a multi-session cd, leave out -multi.

Burning a multi-session ISO

Again, as said above, you have to have a CD containing data already before going to this step. If you burned using the -multi flag and still have enough room on your CD for the next session, then:

cdrecord dev=ATAPI:0,1,0 -v -multi -pad -data output1.iso

mksifos & cdrecord together (piping)

The output of mkisofs can also be piped to cdrecord to burn "on the fly". This means that there is no actual iso image generated, but that the iso being created is written directly to CD.

Advantages:

  • Faster (for a single burn) ~ mkisofs writes it's images faster than cdrecord can burn, meaning the only time taken is the time it takes to burn, and not write an image and then burn.
  • Saves temporary space. If you have 650MB's of data waiting to be burned, and ISO image will also require 650MB's, meaning you have to have that amount of free space to burn.

Disadvantages:

  • buffering an image and burning is more intensive than just burning itself. This can lead to buffer-underruns meaning a coaster instead of a nice new CD.

However, having said that, most systems these days can handle it without a problem (even my old 233MHz with 64MB RAM managed).

So how do we pipe? Easy ... almost exactly like the above commands, except we state no output file with mkisofs, and use a - (meaning from a pipe) with cdrecord instead of the iso name.

mkisofs -J -r dir_with_files/ | cdrecord dev=ATAPI:0,1,0 -v -multi -pad -data -

Audio CD's

Audio CD's are burned slightly differently than data CD's. Probably the best way to do it is to first rip all the audio tracks to your harddrive as WAV files, and then use cdrecord to burn them to your CD.

Ripping an Audio CD to harddrive

We will use cdparanoia to rip our tracks. Firstly, insert your music CD into your cdrom, and using it's devive filename (my cdrom is /dev/hdc):

cdparanoia -Q -d /dev/hdc
cdparanoia III release 9.8 (March 23, 2001)
(C) 2001 Monty and Xiphophorus

Report bugs to paranoia@xiph.org
http://www.xiph.org/paranoia/

Table of contents (audio tracks only):

track       length              begin         copy  pre ch
===========================================================
 1.    23332 [        0 [00:00.00|05:11.07]]    no   no  2
  2.    38168 [   23332 [05:11.07|08:28.68]]    no   no  2
  3.    27535 [   61500 [13:40.00|06:07.10]]    no   no  2
  4.     2910 [   89035 [19:47.10|00:38.60]]    no   no  2
  5.    27317 [   91945 [20:25.70|06:04.17]]    no   no  2
  6.     8488 [  119262 [26:30.12|01:53.13]]    no   no  2
  7.    20525 [  127750 [28:23.25|04:33.50]]    no   no  2
  8.     4215 [  148275 [32:57.00|00:56.15]]    no   no  2
  9.    24320 [  152490 [33:53.15|05:24.20]]    no   no  2
 10.    10287 [  176810 [39:17.35|02:17.12]]    no   no  2
 11.    44678 [  187097 [41:34.47|09:55.53]]    no   no  2
 12.     6477 [  231775 [51:30.25|01:26.27]]    no   no  2
 13.    29968 [  238252 [52:56.52|06:39.43]]    no   no  2
 14.    18007 [  268220 [59:36.20|04:00.07]]    no   no  2
 15.    62050 [  286227 [63:36.27|13:47.25]]    no   no  2
 TOTAL  348277 [77:23.52]    (audio only)

This simply just shows us that that the CD is detected correctly as an audio CD. Now we will 'cd' to a temporary directory and rip the songs to the harddrive:

$ cd /tmp
$ cdparanoia -d /dev/hdc -w -B
cdparanoia III release 9.8 (March 23, 2001)
(C) 2001 Monty  and Xiphophorus

Report bugs to paranoia@xiph.org
http://www.xiph.org/paranoia/

Ripping from sector       0 (track  1 [0:00.00])
          to sector  348276 (track 15 [13:47.24])

outputting to track01.cdda.wav

 (== PROGRESS == [        >                    o| 006869 00 |] == :-) o ==)

outputting to track02.cdda.wav

 (== PROGRESS == [ >                           0| 026446 00 |] == :-) 0 ==)

.....

Done.

When the rip is complete, you can test the way files with:

play track01.cdda.wav

It should play the first song... and so on. YOu don't need to test them all unless you have a scratched CD, or cdparanoia complained during the rip about unreadable data.

Burning the audio tracks to the CD

It is important to note the -audio flag we need to use. If you don't specify this, you will be left with physical wav files on your CD ;-)

cdrecord dev=ATAPI:0,1,0 -v -audio track*wav

Also, the above command will burn all the track*wav files in the order of 'ls', so if you want to change the order, or have several wav files with different names, you will have to name them like

cdrecord dev=ATAPI:0,1,0 -v -audio track01.cdda.wav track01.cdda.wav middle.wav last.wav

... relative to their actual names of course.
This method does have a disadvantage though, being that of the 2-second gaps between tracks. This is the result of image-padding (each image is rounded up to the nearest "whole number", to create separate images all independent of eachother). This can be very annoying, especially with live recordings of concerts and such. For this we need to use Disc-At-Once.

Track At Once or Disc At Once

Burning a CDDA as above will do so in "Track At Once" mode. The first audio track is written, the laser is switched off, data for the next track is buffered, then the laser is switched on again to write the track, etc... This will introduce a 2 second pause between tracks, which may be undesirable in some circumstances such as when transcribing a live recording, where a pause between tracks definitely will be noticed.

The solution is to write the CD in what is known as "Disc At Once" (or "DAO") mode in which, as its name suggests, the disc is written in one fell swoop with no pause between tracks. The "-dao" command line option of cdrecord achieves this, so the command line used above to burn those 18 audio tracks to the CD in DAO mode would be:

cdrecord dev=ATAPI:0,1,0 -v -dao -audio track*wav

Conclusion & extra reading

This HOWTO should hopefully get you started anyway with your burning. It is (as I explained) not a HOWTO for all the used programs, and there are many many extra options you can add to the commands above. From what I have tested, all the above commands work, and the results are what was expected.

Some tutorials add extra padding (forinstance on audio tracks), etc etc, however I did it without and got the same results. Perhaps this is kernel-related, cdrecord/mkisofs version-related, or even CD-writer-related, I don't know.

If you do have problems here, check google with your error message, as you are almost guaranteed not to be the first with such errors, and I can guarantee you there will be solutions out there.



User Comments