Burning CDs under Linux

9th June 2002


I've been able to create data CDs under Linux for a while, and recently learnt how to make audio cds. But there were still some tasks that I didn't know how to do, but were sure could be done. So I did some research.

I started with the Sept/Oct 2000 issue of the now-defunct Maximum Linux magazine. I had used this issue ages ago to learn how to setup the cd burner and make data cds. It had a lot of extra information that was now relevant. Then I looked at the CD-Writing-HOWTO that gets installed in /usr/doc/Linux-HOWTOs under Slackware, and is probably somewhere similar for other distributions. And finally, I read the man pages for cdrecord, readcd, cdrdao and cdda2wav. I find man pages easier to read and understand when I have a bit of a background of the topic.

So now that I know, the trick is not to forget. And that means I have to write a web page so that I can refer back to it.

Setting up a burner


The essence of doing this is to set your system up for a SCSI cd burner. If you actually have a SCSI cd burner, then your system should work as is. If you have an ATAPI cd burner like most of us, then you have to build a special kernel and fake the SCSI.

If you don't know how to build a kernel, it's time to learn. I'll give rough instructions here, but you should investigate further and learn what to do. See your distribution manual, or read the O'Reilly book by Matt Welch Running Linux or use any of the thousands of tutorials that can be found on the Web by doing a Google search.

  • log on as root
  • change directory to /usr/src/linux
  • configure the kernel. There are three ways to do this. It's your choice.
    • "make config" for the painful command line method. Avoid this.
    • "make menuconfig" for the curses based configuration program. I use this. It's fast and convenient.
    • "make xconfig" for X based configuration program. This is very similar to the curses version, but prettier.
  • Set these features
    • Block devices
      • turn ON Loopback device support
    • ATA/IDE/MFM/RLL support
      • IDE, ATA and ATAPI Block devices
        • turn OFF IDE/ATAPI CDROM support
        • turn ON SCSI emulation support
    • SCSI support
      • turn ON SCSI support
      • turn ON SCSI CDROM support
      • turn ON Enable vendor specific extensions
      • turn ON SCSI generic support
    • File Systems
      • turn ON ISO 9660 CDROM file system support
      • turn ON Microsoft Joliet CDROM extensions
  • compile the new kernel
    • make bzImage
    • make modules
    • make modules_install
  • backup your old kernel, because you might need it: "cp /boot/bzImage /boot/bzImage.good
  • put the new kernel into place with "cp /usr/src/linux/arch/boot/i386/bzImage /boot"
  • edit /etc/lilo.conf to allow access to the previous working kernel
  • run "/sbin/lilo"
  • reboot and hope it worked

Determining what SCSI device the burner is


This is easy. Run "cdrecord -scanbus" as root, and look at the output. There should be enough there to tell you which device the burner is. Here's my output:

root@cerebus:/usr/src/linux/$ cdrecord -scanbus
Cdrecord 1.10 (i686-pc-linux-gnu) Copyright (C) 1995-2001 Jörg Schilling
Linux sg driver version: 3.1.17
Using libscg version 'schily-0.5'
        0,0,0     0) *
        0,1,0     1) *
        0,2,0     2) 'HP      ' 'C5100A          ' 'R030' Processor
        0,3,0     3) *
        0,4,0     4) *
        0,5,0     5) *
        0,6,0     6) *
        0,7,0     7) *
        1,0,0   100) 'SAMSUNG ' 'DVD-ROM SD-612  ' 'ST02' Removable CD-ROM
        1,1,0   101) 'YAMAHA  ' 'CRW8824E        ' '1.00' Removable CD-ROM
        1,2,0   102) *
        1,3,0   103) *
        1,4,0   104) *
        1,5,0   105) *
        1,6,0   106) *
        1,7,0   107) *

This shows I have two SCSI buses. The first one I know is a real SCSI card in my machine, the one that is attached to my Hewlett Packard photo scanner. The second one is the emulation SCSI device. It has two devices on it and that pretty clearly shows me that my Yamaha CD burner, model CRW8824E, is device 1,1,0. So for all examples below, when I want to burn, I use dev=1,1,0. And if I want to read CDs in the DVD drive, I would use device dev=1,0,0.

Burning a data cdrom


This is easy. Like much of cd burning work, it is a two step process:

  1. create an ISO image
  2. burn that ISO image to the cd

Step 1 - create an ISO image

The first step will create a large file containing the files and directory structure that you want on the cdrom. The program to use is mkisofs - MaKe ISO File Structure. If you look at the man page for mkisofs, you'll see that it takes a lot of options. I use a very limited set of the options. Here's the commonest form of what I use.

mkisofs -r -o cdimage.iso /home/hgriggs

I specify -r to set up the file permissions in the simplest and most useful way on the cdrom. -o is the name of the file that gets created. And at the end I list a directory that contains the file structure I want put on cdrom. When this finishes, I check the ISO image to see that it contains what I expected, by mounting it. This is a feature that I appreciate very much.

mount -t iso9660 -o loop cdimage.iso /mnt/dummy

and then I can rummage around inside the ISO image and make sure it's all set up correctly before I burn it.

Step 2 - burn the ISO image to cdrom

The second step is to burn the ISO image to a blank cdrom.

cdrecord -v speed=n dev=x,x,x -data cdimage.iso

Set the speed to what your burner will take. I usually use 8 because my burner is rated at that. And set the dev= to the correct values for your burner. "cdrecord -scanbus" is your friend. See how to determine your device.

Burning an audio cdrom


This is also easy. Again, this is a two step process, but the first step is very different:

  1. collect your sound files
  2. burn the sound files to the cd

Step 1 - collect sound files

The first step is what takes me a lot of time. If I am collecting songs from a cd so I can build a compilation cd, then it's no big deal. I use cdparanoia to rip the cds from the original cds. However, I spend a lot of time digitising audio tapes and vinyl.

What you ultimately want is raw PCM data. This data is usually wrapped inside a very primitive structure, and the result has a WAV extension and is called a wav file. cdparanoia will create the PCM data and wrap it automatically in the WAV structure. Most recording programs will do the same thing.

Getting audio tracks from an audio cd

I use cdparanoia to get the tracks off the audio cd. You need to read the man pages of cdparanoia for the fine details. Here's some examples of what I do:

Extract track 4 from a cd and have it named track04.cdda.wav cdparanoia -B 4
Extract tracks 3 to 5 from a cd and have them named track03.cdda.wav, track04.cdda.wav and track05.cdda.wav cdparanoia -B 4-5
Extract tracks 2 and 4 from a cd and have them named track02.ccda.wav and track04.cdda.wav cdparanoia -B 2; cdparanoia -B 4

cdparanoia has many more options. Read the man page for how to name the tracks as you go.

Getting audio tracks from other sources

This is where it gets tricky. You have to produce PCM data that is stereo, 16 bit digital audio, sampled at 44100 Hz. Most of your recording programs will do this. I use yarec for my recording, and use this command line to record a track:

yarec -r 44100 -b 16 -c 2 -f -n track01.wav

-r sets the sampling rate (44100), -b sets the sample size in bits (16), and -c sets the number of channels (2 for stereo).

If you use other recording programs, you can set the same parameters. I have dabbled with sox and snd and both these do a nice job. I have also fiddled with the Gnome and KDE utilities and again, these do a nice job. But I keep coming back to yarec because I can write scripts around for when I am digitising an entire LP or tape and I want to insert the track breaks.

Before you can use yarec, you need to set the input channels and the sound levels. I use aumix for this. There are plenty of other programs, but I like aumix.

I used the Linux Journal Press book The Book of Linux Music and Sound by Dave Phillips, to help me get through the learning process of building your own audio files. I strongly recommend this book.

[Linux Music
  And Sound]

Step 2 - burning the tracks to an audio cd

cdrecord will create an audio cd for you. I use a command like this:

cdrecord -v speed=n dev=x,x,x -pad -audio doors_morrisonhotel.wav doors_lawoman.wav

I use -pad because most of the tracks that I create myself from non-cd sources do not have an integral number of blocks (man cdrecord to understand that), -pad will clean that up for me and pad the data. All files specified after -audio are assumed to be audio files. What sort is determined by the extension. I use WAV files, so that works out fine.

Ordering the tracks

When you go to burn your tracks to an audio cd, the tracks will appear on the cd in the order you specify them when you call cdrecord. You can name them one after the other if you like, as I did in the above example, but I find that tedious. I usually rename the tracks so that when I ls the directory, they appear in the order I want them. Take the above example. If I rename the two tracks to be 01_doors_morrisonhotel.wav and 02_doors_lawoman.wav, then I can simply use the cdrecord command:

cdrecord -v speed=n dev=x,x,x -pad -audio *.wav

Copying a data cdrom


Copying a cd, data or audio, requires two passes. I reckon that even the slick Windows programs require two passes.

False shortcut

There is one short cut method if you have a cd player and a cd burner. You can suck and spit in the one operation with

cdrecord -v dev=x,x,x speed=x -isosize /dev/player

You have to fill in the numbers for dev=x,x,x, so see above for how to determine the numbers. Set the speed to whatever you normally set it at. /dev/player is the player device. Change that to fit your circumstances.

I have used this, but not successfully. I don't think my DVD player is fast enough to keep the data coming in to the burner.

Two-pass method

I think it's best to use a two pass method:

  1. suck the data to hard disk
  2. write to burner
Reading from a hard disk is a lot faster than reading from a cdrom. I prefer to do all this stuff in two passes anyway.

Step 1 - getting the data to hard disk

I tried a number of different methods of getting the data to hard disk. I used dd, but wasn't happy with the results. Then I tried readcd, a utility that comes with cdrecord.

Attempting dd

The first method I tried of getting the data from the cdplayer was with dd.


dd if=3D/dev/sr0 of=3Dcdimage

I did this and got an error at the very end. However when I mounted the image I had created, it looked fine. "mount -o loop -t iso9660 cdimage /mnt/test". It looked okay, but I didn't trust it, so I don't use this method any more.

Using readcd

There is a utility that comes with cdrecord called readcd. This is nice. It gives a nice count of the reading, doesn't give any errors and is my preferred way of sucking a cd to hard disk.

readcd dev=x,x,x f=cdimage

You have to setup the dev=x,x,x yourself, using "cdrecord -scanbus" to determine what SCSI devices you have. See above.

Step 2 - burn to cd

The second step is to burn the image you have created to cdrom with cdrecord. I use

cdrecord -v speed=x dev=x,x,x -data cdimage

and that works very nicely. If you want to check your work before you attempt a burn, mount the ISO image with "mount -o loop -t iso9660 cdimage /mnt/test". Then cd to /mnt/test and check that it's all there. If you're happy with the arrangement, umount the image, then burn.

Copying an audio cd


Again, a two pass method is required.

  1. get all the data from the audio cd as WAV files
  2. burn them to new cd

Obviously, the new audio cd will not be an exact bit for bit copy of the original. But it will be close enough.

Step 1 - get the audio tracks

There are a number of ways of doing this. cdparanoia will do it. cdda2wav (comes with cdrecord) will also do it.

Using cdda2wav

I started with cdda2wav. This produces a lot of screen information and seems slow but does a nice job. It will produce audio.inf and cddb files, but I turn these off with -H.

cdda2wav -D /dev/sr0 -B -H

This will produce a bunch of tracks in the format audio_nn.wav. There are lots of options with this program. One of them is to echo to the soundcard. You can play while you rip. I haven't tried this. Too junky for me.

This pair of programs, cdda2wav and cdrecord, work well together. But I'm used to cdparanoia for my ripping, so I thought I would try it too.

Using cdparanoia

Cdparanoia was originally based on cdda2wav. It uses similar commands and works just fine. I used

cdparanoia -B

and the -B is the same as with cdda2wav. However it starts with track0 and gives some weird data for track 0, before getting stuck into the real audio sound on track 1. So it's best to use

cdparanoia -B 1-

which starts at track 1 and goes to the end. I found that this occasionally shows bad data in the very first read of the cd, but Ctrl-C and restart clears that up. cdparanoia will produce WAV files with a filename format of tracknn.cdda.wav. Again, they are in the right order, ready to be burnt to an audio cd with cdrecord.

Interestingly, cdparanoia produces exactly the same size files as cdda2wav does, so either that reflects the common origin, or the PCM data is the same regardless of what extracts it.

Step 2 - burn the tracks to cd

Once you have the WAV files in a directory, you can burn the audio cd with

cdrecord -v speed=8 dev=1,1,0 -pad -audio /data/mp3/build/*.wav

You have to pad the files (-pad) so the WAV files are in the right size for the cd burning. The tracks on the audio cd will be in the normal ls order of the tracks you specify, so name them so they will ls in the correct order and you'll be fine. The output of cdda2wav is already in the right order. If you're making a mix and match type of cd, like a greatest hits, then you rename them to be in the order you want.



I can now duplicate data and audio cds under Linux. I am unsure if this works with bootable cdroms. This is something I will test later.

I am much happier now that I know this. I can write my little scripts and automate a lot of this. There are front ends that do all that for you and I plan on investigating them. However, front ends hide information and I don't like that. If I wanted a GUI front end to hide tricky details, I would be using Windows. Little scripts are much handier.