Creating data and audio CDs in Linux

Creating audio CDs

Copy audio tracks into .wav files
  1. Connect line output from tape deck or other audio source to 'line in' of sound card through an equalizer. Set level to -12dB or as needed to eliminate distortion.
  2. Digitize tape by sampling audio source at 44100 samples/sec and create a .wav file for each track using the command
         /usr/X11R6/bin/wavrec -t 3600 -s 44100 -S test01.wav          
    • -S indicates stereo. Contrary to what the man page says, the default is not stereo but mono. File must be in stereo to create an audio CD.
    • -t is seconds. Set to a large value and press ^C after each track.
    • -s 44100 is 44100 samples/sec, which is standard for audio CDs. You must use 44100 to create an audio CD.
    • One hour will take approx. 633 MB. Wavplay/wavrec is an orphan program, and does not seem to have been updated since version 1.4, but is more convenient than newer programs like audacity, because it doesn't have a cumbersome GUI. However, it often creates wav files that are defective (i.e., with short skips presumably caused by buffer underruns). Thus it is important to check the file before committing it to a CD.
    The command
         rec -d /dev/dsp -v 0.3 --rate=44100 test.wav                  
    also creates a file, but on my system the sound was always distorted for some reason, even with the volume set as low as 0.3 (maximum is 100). Other software that could be used includes
    • amp
    • cat /dev/dsp > soundfile
    • lame (MP3 encoder)
    • sound-record
    • audacity (newer, but runs in a GUI, which means you can't run it from a script to capture more than 2 hours of sound; however, it reportedly can record up to 32-bit samples in more than 2 channels, and has extra features like pitch/tempo adjustment).
    • sox (command-line program; records and interconverts audio file formats; orphan software, not updated since 1995)
    • soundstudio (uses sox; runs in a GUI; also, only available as an rpm)
    • yarec
    • slab (has GUI)
    • snd
    • dd (copy a file from /dev/audio)
    • cdda2wav (recovers audio tracks from CDs)
    • cdparanoia (recovers audio tracks from CDs)
    Occasionally /dev/dsp gets screwed up using these alternate methods. For example, with 'rec', if the rate is set to 64000, /dev/dsp locks up and you must reboot. The CD playing program `xmcd' also hangs /dev/audio if it crashes, forcing a reboot. If /dev/dsp hangs, the symptoms include:
    • 'rec' creates a file size of zero
    • Sound files cannot be played.
    • Sound is extremely distorted
    • Sound files play at the wrong speed.
  3. Check the .wav file parameters with wavplay to make sure file is the correct type.
       /usr/X11R6/bin/wavplay a01.wav                        

All the above methods also share the deficiency that no indication is given as to the amplitude of the signal during recording. Thus, it is necessary to play around with xmixer settings and make frequent test recordings to avoid recording an hour of dead silence or clipped sound.

Another problem is that waverec cannot create files larger than 2 GB. This means you can't record more than about 3 hours at a time.

NOTE Before recording, edit /etc/crontab to ensure that the system doesn't start running cron jobs in the middle of your recording. This will cause wavrec to quit prematurely.

Also note that recording or playing an audio file will seriously slow down your system clock. Thus, these programs should never be run on a production server.

Repair .wav files if necessary

  1. ecawave = graphical audio file editor with cut and paste.
  2. ecasound = text-mode file format interconversion. Example:
     ecasound  a04.wav -erc:1,2 -o:test.wav
    converts file a04.wav from mono to stereo and writes the result in file test.wav.

NOTE cdrecord is a link to wodim. For some reason, recent distros no longer create this link, and you have to use wodim instead of cdrecord. Or just make the link yourself.

Copy the .wav files onto CD with cdrecord

  1. Recompile kernel if necessary to enable CD-RW to work. In some kernel versions, recording of sound does not work. For SONY CD-RW CRX175E ATAPI CD/DVD-ROM drive, the following must be set:
         CONFIG_BLK_DEV_IDECD=y (In IDE, ATA and ATAPI Block devices)
         CONFIG_BLK_DEV_SR=y  (In SCSI support type) (disk, tape, CD-ROM)
    Since ATAPI is way of sending SCSI commands over IDE, Linux must be configured to use a SCSI driver (ide-scsi) to communicate with the ATAPI CD-RW device. Use 'dmesg' to determine the device name assigned (/dev/sr0 or /dev/scd0) to it. If the CD-RW is identified as /dev/hdd this means it is not configured properly. Check by typing 'eject /dev/sr0'.
  2. Add the following line to /etc/lilo.conf to ensure that the CD-RW is identified as SCSI at boot-up:
         append = " hdd=ide-scsi"                                      
         append = " hdd=ide-cd"                                        
    (this is supposedly preferred, but I still use "ide-scsi"). Then type '/sbin/lilo' and reboot. At boot-up, it should say:
       ide_setup: hdd=ide-scsi                                         
    and something like:
       scsi0 : SCSI host adapter emulation for IDE ATAPI devices
       Vendor: SONY      Model: CD-RW  CRX175E    Rev: 1.1a
       Type:   CD-ROM                             ANSI SCSI revision: 02
       Attached scsi CD-ROM sr0 at scsi0, channel 0, id 0, lun 0
       sr0: scsi3-mmc drive: 32x/40x writer cd/rw xa/form2 cdda tray   
    This 'append' step is essential for cdrecord -scanbus to identify an writable ATAPI CD drive. If you use "ide-cd", this supposedly allows you to specify dev=/dev/hdX as the device (I didn't test this).
  3. Find out where your CDRW is located:
       cdrecord -scanbus                                               
    For example, for an external USB CDRW drive, we got:
            0,0,0    0) 'HP      ' 'C2520A    ' '3503' Processor
            0,1,0    1) *
            0,2,0    2) *
            0,3,0    3) *
            0,4,0    4) *
            0,5,0    5) 'IOMEGA  ' 'ZIP 250   ' 'H.41' Removable Disk
            0,6,0    6) *
            0,7,0    7) *
            1,0,0  100) 'LITE-ON ' 'LTR-52327S' 'QS58' 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) *    
    So the parameters were 1,0,0.
    On a system with an internal rewritable ATAPI CD drive, we got:
            0,0,0   0) 'SONY' ' CD-RW CRX175E' '1.1a'  Removable CD-ROM
            0,1,0   1) *
            0,2,0   2) *
            0,3,0   3) *
            0,4,0   4) *
            0,5,0   5) *
            0,6,0   6) *
            0,7,0   7) *
            1,0,0   100) 'Maxtor' '5000DV v01.00.00' '0100' Disk
            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) *  
    and the parameters were 0,0,0. If the "append" statement had been omitted from lilo.conf, only the Maxtor 5000 DV would have shown up in this list.
  4. Alternatively, you can use dmesg to determine the channel, id, and lun of the CDRW drive:
         dmesg | grep lun
         Attached scsi CD-ROM sr0 at scsi0, channel 0, id 0, lun 0     
  5. Edit /etc/fstab to make it read-write:
        /dev/cdrecorder /media/cdrecorder   auto  noauto,user,exec 0 0
        /dev/sr0        /media/cdrecorder   auto  noauto,user,exec 0 0 
  6. Insert blank CD and issue the command (as root):
        cdrecord -dao dev=0,0,0 -audio -copy -pad  test.wav            
    giving the SCSI bus, ID, and LUN parameters.

    To create 10 indexes at 5-min intervals:
         cdrecord -dao dev=0,0,0 -audio -copy -pad index=0, \
         22500, 45000, 67500, 90000, 112500, 135000, 157500, \
         180000, 202500 test.wav                                       
    To create an audio CD containing multiple tracks, with each track in a separate file:
        cdrecord -v -dao dev=0,0,0 -audio -copy -pad a*.wav            
    (-v = verbose). The disadvantage of this is that you have to record each track manually. Make sure the files are named in such a way that they are recorded on the CD in the correct order (e.g., a01.wav, a02.wav, etc). Try not to do anything disk- or processor-intensive while it is burning a CD. Never burn CDs on an important production machine - if an underflow occurs, the operating system will hang.

    Note that some of the options are preceded by a dash, and some are not.


Cdrdao is another program for recording CDs. The advantage of cdrdao is that it is possible to add text information to the CD, if your drive supports it. You would create a Table of Contents (.toc) file containing the name of the .wav file and other information. The disadvantage is that it is harder to use, and does not work on all CD-RW devices. I could never get cdrdao to produce a viable CD on a SONY CRX175E.

  1. Read toc data from existing CD to create a sample toc file
      # cdrdao read-toc --driver generic-mmc aaa.toc                
  2. Modify the toc file to match the information from the audio source.
  3. Check to see if toc file is accepted by cdrdao.
      # cdrdao show-data --driver generic-mmc aaa.toc               
    Should spew out an endless column of numbers.
  4. Burn a CD
      # cdrdao write --device 0,0,0 --driver generic-mmc aaa.toc    
  5. Throw CD away. (cdrdao doesn't actually work on my system; writes a couple of tracks then stops, ruining the CD. Your mileage may vary.)

Note that the software is inconsistent with regard to options; options may require 0, 1, or 2 hyphens.

Adaptec Easy CD Creator (Windows)

I had no luck whatsoever with this program. It seems to dislike .wav files for some reason and refused to let me drag them into its little window, insisting that the sound files were in fact incoming faxes. It also takes a very long time to start up. Even worse, it only runs under Windows. It has a nice icon though.

Creating data CDs

Cdrecord (also known as wodim) can burn CDs and recordable/rewritable DVDs.

  1. Find out where your CDRW is located:
         cdrecord -scanbus 
  2. Get CD-RW drive to work as described above.
  3. Create a tree with the desired files and check the size using du.
  4. Make sure the names conform the the DOS 8.3 format used by CDs so that Windows and DOS can read the CD; or use the -iso-level 3 option below if you don't care about DOS compatibility.
  5. Create a ISO 9660 filesystem with Rock Ridge extensions:
      mkisofs -f -J -R -iso-level 3 -o cdimage.raw ./tree 
    ./tree = path to data to be placed on CD
    -f = follow symlinks
    -J = Joliet extensions (necessary to read long filenames in Windows *)
    -iso-level 3 = remove restrictions on filenames
    -o cdimage.raw = filename to create
    -R = Rock Ridge extensions
    * Without this option, filenames with more than 32 characters will be truncated and/or mangled when the CD is opened in Windows.
    If the directory was created by a Windows user, there may be long filenames with spaces. In this case, it's necessary to use the -joliet-long option:
       mkisofs -f -J -joliet-long -R -iso-level 3 -o cdimage.raw ./tree   

     genisoimage -f -J -joliet-long -R -iso-level 3 -o cdimage.raw ./junk   

  6. Test to make sure it is mountable. Mount it read-only (-r) using the loop device (-o loop).
           mount -r -t iso9660 -o loop cdimage.raw /mnt
           ls -l /mnt
           umount /mnt     
  7. Burn the CD
    cdrecord -v dev=0,0,0 cdimage.raw
    For the external USB CDRW the command was:
    cdrecord -v dev=2,0,0 cdimage.raw
  8. Test the CD. There is nothing worse than an unreadable backup.

Copying a CD in Linux

CDs can be easily copied using the dd and cdrecord commands. Put the CD in the CD reader, but don't mount it.
1. Use dd to make a local copy.
  dd if=/dev/cdrom of=mycd.iso

2. (Optional) Verify that the copy is good.
  mount -r -t iso9660 -o loop mycd.iso /mnt
  ls /mnt
  /umount mycd.iso 

3. Then copy it as described above.
  cdrecord -v dev=2,0,0 mycd.iso speed=0

The process is easier than creating a new one, since the file is already in ISO 9660 format. A GLIB-based program called xcdroast is available that handles these commands automatically. However, it is not easy to compile on some systems. The "speed=0" option is only needed on slower systems.


Sometimes it says:
  cdrecord: DMA speed too slow (OK for 12x). Cannot write at speed 24x.
  cdrecord: Max DMA data speed is 12.
  cdrecord: Try to use 'driveropts=burnfree'.

Solution: add the option "speed=0" or "speed=2".

Recording an ISO file directly to CD/DVD
If you already have a properly-formatted .iso file, you can burn it directly to a CD. This is sometimes necessary for DVDs, which are often too big for mkisofs.
    cdrecord dev=/dev/cdrw1 speed=44 driveropts=burnproof -eject -v cdimage.raw 


    cdrecord dev=/dev/sg2 speed=44 driveropts=burnproof -eject -v cdimage.raw 

Ya takes yer chances with this method. If the .iso file isn't correct, you might create a tiny Frisbee instead.

Playing Audio CD

  1. Use alsamixer or amixer to set the levels of the sound card. If the levels are not set, CDs will be played at a very low volume level which results in an audible hissing sound.
  2. Play CD with xmcd.


Ripping audio CD to .wav file (-v = verbose  -B = batch, 
each track to a different file):
   cdparanoia -vB
Recording audio input to .wav file:
   /usr/X11R6/bin/wavrec -t 3600 -s 44100 -S a01.wav
Repairing .wav files (graphical):
Converting a track from mono to stereo:
   ecasound  a04.wav -erc:1,2 -o:test.wav
Burning new CD using .wav files:   
   cdrecord -v -dao dev=0,0,0 -audio -copy -pad a*.wav
Checking and playing .wav file:
   /usr/X11R6/bin/wavplay a01.wav