Linux Know-How provides a collection of introductory texts on often needed Linux skills.


Writing CD-R/Ws

Disclaimer: Copying copyrighted material is illegal. Do NOT use the instructions below for anything illegal.

Writing CDs used to be tricky, but these days I simply use (as root, in X terminal):

xcdroast &

If it works for you as it works for me, you don't need to read any further.

Perhaps still useful if xcdroast does not work on your system, here are the steps I once followed to write CDs using command-line tools. Please note that xcdroast is just a graphical front-end to the command line tools described below, so it will not work if the commands do not work. My only complaint s were that my low-cost, no-name "12x 8x 32x" CD-RW writes at top speed of 12x (for CD-R) but reads only at the speed of 2x (instead of 8x forCD-RW), and rips audio at 1x, no matter what I do.

o All setup has to be done as root. Newer distributions (e.g. RedHat 8.0) may require no setup at all.

o Check your boot files if they pass a parameter to the kernel with the information that you have the ide-scsi drive: "hdb=ide-scsi". If required, add to the file

/etc/lilo.conf or /boot/grub/grub.conf (depending which boot loader your system uses):

the option "hdb-ide-scsi" so that the line looks like this:

append="hdb=ide-scsi" #(for /etc/lilo.conf, at the end of the Linux "image" section)

kernel /boot/vmlinuz-2.4.7-10 ro root=/dev/hda6 hdb=ide-scsi #(for /boot/grub/grub.conf)

Adjust the line above if your CD writer is not "hdb" (second drive on the first IDE interface). It makes your IDE-ATAPI CD-W(R) to be seen on your Linux system as a SCSI device. (It is not really a SCSI device, it is an IDE device, it just pretends to be SCSI.) Run lilo after making any changes to /etc/lilo.conf . Grub does not need re-running.

  • Add the loop devices to the /dev/ directory if it is not present. This is not a obligatory, but a nice feature if you plan creating your own data CDs. The loop device will let you mount a CD image file (as if it was a already a file system) to inspect its content. The loop devices don't exist on my hard drive after Linux RedHat installation, so I create them using:

cd /dev/

./MAKEDEV loop

  • Make sure that appropriate modules are loaded to the kernel using:

lsmod

If required, add these two lines at the end of the file /etc/rc.d/rc.local so that the needed kernel modules are automatically loaded on system startup:

/sbin/insmod ide-scsi

/sbin/insmod loop

These two kernel modules are needed for SCSI emulation of IDE drives and to support the loop devices, respectively.

  • Check, create or modify the device /dev/cdrom so it now points to the correct device , most likely:

ls -l /dev/cdrom

ln -s /dev/scd0 /dev/cdrom #(if required)

You may need to do this because "/dev/cdrom" pointed to an IDE device (probably /dev/hdb) but now this changes since your CD-R is going to be in SCSI emulation mode.

There is also /dev/cdwriter that you may want to point to /dev/cdrom although it is not necessary on a single CD drive system:

ln -s /dev/cdwriter /dev/cdrom

  • Reboot so that the changes to /etc/lilo.conf take effect. Check if your CD-R(W) still works properly for normal reading.

  • Check if the program cdrecord is installed, e.g.,:

cdrecord -scanbus

If it is not installed, download the program "cdrecord" from your favorite Linux software repository (e.g., http://idirect.linuxberg.com/ ). Then install the source code, compile it, install the program, and make symbolic links so that the executable are easy to run (the installation would be much easier if you found a binary *.rpm file):

cd /usr/local

tar -xvzf /the_path_to_which_you_downloaded/cdrecord-1.6.1.tar.gz

ls

cd cdrecord-1.6.1

make

make install

ls /opt/schily/bin/

ln -s /opt/schily/bin/* /usr/local/

The program cdrecord is a spartan, command line utility for writing CD. There are several GUI front ends to it, but they will be useless if the underlying cdrecord does not work properly. My advice: use command line for some time--you get to understand how things work, get flexibility, and reliable results. Then you can install GUI front ends to make CD covers, and make things easier for Windows-educated users on your system.

  • See if your cdwriter is recognized. If it is, it should now show in the output from this command:

cdrecord -scanbus

  • Create a CD image containing your data:

mkisofs -r -o cd_image input_data_directory

This makes an International Standard Organization (ISO) standard 9660-type file system containing the files from input_data_directory, but writes the file system to an ordinary file on the hard drive. This output file is an "image" of the new CD which I am creating. The option "-o" indicates that the parameter that follows is the output filename of this image. The option "-r" enables "Rock Ridge" extensions to the ISO protocol so that file attributes are saved, and it sets the file permissions so all the files on the CD are publicly readable (can be read by all user, not only the file owner). The filenames are abbreviated to the "8.3" DOS-type length but, since Linux supports so called "Rock Ridge" extensions to ISO9660, it also writes the full names and all the file permissions as well--this way the new file system is portable across all popular operating systems (DOS, MS Windows, Linux, UNIX, etc)--really convenient to the user.

The input data directory can be assembled from different directories and files from all-over your file system using symbolic links (saves harddrive space because the data is not copied), but if you do it you probably want to tell mksiofs to follow symbolic links using the option -f:

mkisofs -r -f -o cd_image input_data_directory_containing_symlinks

  • You may want to inspect the CD image file by mounting it through the loop device:

mount -t iso9660 /dev/loop0 cd_image /mnt/cdrom

[now the content of the file should appear in /mnt/cdrom]

cd /mnt/cdrom

[inspect the file mounted through the loop device]

When done with inspection, change your working directory away from the mountpoint and unmount the file:

cd

umount /mnt/cdrom

  • If everything worked, you may burn your data CD:

cdrecord -v speed=8 dev=0,0,0 -data cd_image

The first number in "dev=" stand for the scsi bus number (the first one is 0, second bus is 1, ...), device id on the scsi bus (between 0 and 7), and the scsi lun number (always 0) respectively. You must customize them: the first two numbers can be read in the output from cdrecord -scanbus, the third number is always 0. Make sure to use the correct numbers or you may write to a wrong drive and corrupt your data.

The timing of writing to CD-Rs is very important, or an error may occur (the laser cannot be switched on and off at will). Therefore avoid doing intensive tasks during creating a CD, e.g. don't create or erase large files on the hard drive. My old system (RH6.2) will not permit me to start new tasks when using cdrecord .

In a similar way, I can burn a CD from an ISO CD image downloaded from the Internet. One source (a Debian FAQ) recommends the following command (as root) to burn the image "binary-i386-1.iso" to a CD:

nice --18 cdrecord -eject -v speed=2 dev=0,6,0 -data -pad binary-i386-1.iso

This assigns a very high priority ("niceness" of minus 18) to the CD burning task (thus minimizing the possibility of an error).

  • Audio tracks have to be in files of *.cdr (I guess it is the same as *.cdda.raw), *.wav (wave), or *.au format before you can write them to a CD.

  • The utility sox converts between the various audio file formats (sox understands quite a few of them). For example, I can convert a .wav file to a .cdr file:

sox my_file.wav my_file.cdr

You don't need to do the conversions manually - cdrecord supports *.wav and *.au directly (it does a conversion from *.wav or *.au to *.cdr "on the fly"). This is very convenient because audio files tend to be large.

  • Audio CDs don't contain a file system, they store "raw data". This means that you cannot mount an audio CD. Also, each track is written separately, i.e., as if it was a different "partition" on the CD.

  • To read audio tracks from an audio CD and write them to suitable files on your hard drive (typical format is *.raw or *.wav) , you need a "cd ripper". A popular CD ripper is "cdparanoia".

If cdparanoia is not installed, download it. The installation from source goes as follows (I use the autocompletion <Tab> shortcut when typing the long filenames):

cd /usr/local

tar -xvzf /the_path_to_which_you_downloaded/cdparanoia-III-alpha9.6.src.tgz

ls

cd cdparanoia-III-alpha9.6

./configure

make

make install

To rip the first track from an audio CD, I can use:

cdparanoia 1

which will put the first track from the CD into the wave file "cdda.wav" in the current directory.

To rip tracks 1 to 2 from an audio CD to a "raw" file format, I can use:

cdparanoia -B -p "1-2"

The option -B specifies to use a "batch" mode, so that each track is put into a separate file (this is probably what you want, otherwise all tracks would be placed in one output file). The "-p" option specifies output in raw format. The files are named track1.cdda.raw and track2.cdda.raw .

To rip all tracks from an audio CD, each track to a separate *.wav file, while forcing reading speed 4x, I can use:

cdparanoia -S 4 -B "1-"

Make sure you have sufficient free space on your hard drive. You can use use the space on your DOS partition (if you have dual boot).

  • To write suitable audio files to a CD-R(W), I can use:

cdrecord -v speed=8 dev=0,0,0 -pad -dao -audio track*

  • Some audio CDs do not have gaps between individual audio tracks. The easiest way to make a copy of such an audio cd, is to use the utility "cdrdao".

To copy a disk to the file "data.bin" (on my harddrive), and the table of contents to the file "toc-file.toc", I can use this command:

cdrdao read-cd --device 0,0,0 --buffers 64 --driver generic-mmc-raw --read-raw toc-file.toc

To burn the CD from the files I just created, I can use:

cdrdao write --device 0,0,0 --buffers 64 --driver generic-mmc --speed 12 toc-file.toc

Note on re-writeable CDs. Some stereos will not play re-writeable CDs because of the size of the pits on the CDs. For example, my home stereo (JVC) cannot read re-writable CDs (CD-RW) at all, although it will read write-once disks (CD-Rs). Therefore, re-writable CDs may be good to store data but not audio (unless I plan to play them exclusively on my computer).

Mixed-mode CDs (meaning CDs which contain both data and audio, often game CDs) are not a problems, e.g.:

[mount the data part of the mixed-mode CD]

mount -t iso9660 /dev/cdrom /mnt/cdrom

[make an ISO file system from the data on the CD]

mkisofs -r -o cd_image /mnt/cdrom

[unmount the CD]

umount /mnt/cdrom

[rip the content of all audio tracks on the CD, except the first track since it is data]

cdparanoia -B "2-"

[write the data and audio files, piece by piece]

cdrecord -v speed=2 dev=0,0,0 -data cd_image -audio track*

Most CDs can be copied by first copying all data (for data CDs) or all tracks (for audio CDs) onto the hard drive as described before, but some CDs cannot.

For example, these kinds of data (not audio) CDs need to be treated differently: bootable CDs (like Linux installation CD), CDs that require the label, disk with errors, etc. For data CDs, I use these commands to make an exact copy:

dd if=/dev/cdrom of=cd_image

cdrecord -v speed=2 dev=1,0,0 -data cd_image

The dd command copies the input file (if), which in this case is the device /dev/cdrom to the output file (of) which in this example is a file called cd_image (on the hard drive in the current working directory). The second command copies the file cd_image that was created by the dd command onto an empty CD.

For data disk with error, you might want to try:

dd conv=noerror,notrunc if=/dev/cdrom of=cd_image

cdrecord -v speed=2 dev=1,0,0 -data cd_image

The option "conv=noerror,notrunc" specifies that the potential read errors are to be ignored, and files not truncated on error.

For audio CDs, I use these command to make a copy:

[rip the content of all audio tracks on the CD, from track 1 on. The tracks are saved into files in the current directory and named: track01.cdda.wav, track02.cdda.wav, etc.)]

cdparanoia -B "1-"

[write all the audio files to the CD, one by one. The tracks are separated by a 2 s gap]

cdrecord -v speed=2 dev=1,0,0 -audio track*

To copy an audio CDS in the most accurate way, man cdrecord recommends doing this:

cdda2wav -v255 -D2,0 -B -Owav

cdrecord -v dev=2,0 -dao -useinfo *.wav

To make an exact copy of mixed mode CDs:

[The dd command will output an error message when the the data has ended and audio started. This is expected and OK]

dd if=/dev/cdrom of=cd_image

[rip the content of all audio tracks on the CD, except the first track since it is data]

cdparanoia -B "2-"

[Write the data and subsequent audio files, piece by piece]

cdrecord -v speed=2 dev=1,0,0 -data cd_image -audio track*

Re-writable CDs (CD-RW) are used the same way as regular write-once CDs (CD-R), but you have to blank re-writable disks before you will be able to re-use them, e.g.:

cdrecord -v speed=2 dev=1,0,0 blank=fast

To see other (more thorough and slower) options for blanking, use:

cdrecord blank=help

For example this thorough blanking can take 0.5 hour on my system, but is not really necessary unless the old data is confidential:

cdrecord dev=0,0,0 blank=disk

Again, older stereos often will not play CD-Rs.

To simplify writing long commands required by cdrecord (or cdrdao), I may want to define a global alias by placing the following line in the file /etc/bashrc:

alias cdrecord="cdrecord -v speed=2 dev=1,0,0"

Re-login for the changes in /etc/bashrc to take effect. After creating this alias, I can record a CD using the following shortened command (no need to specify the CD writer speed and device name all the time):

cdrecord -audio track*


Last Update: 2010-12-16