1. Andrew's Corner :

CD and DVD Writing from the Linux Command Line

This page aims to provide a gentle introduction to the world of CD and DVD writing from the command line under Linux. Unlike the approach of many such pages available today I aim to present a handful of "task oriented" examples with the idea that such concrete examples will convince most people that the true power of burning under Linux rests solidly on the command line rather than the graphical user interface. Four such examples are in place now:

I hope to produce another few task oriented examples of CD and DVD writing on this page sometime soon. In the meantime please feel free to send me an email with your thoughts about this page, details are at the base of this page.

Making Copies of Your Favourite Linux Distro

Burning a copy of your favourite Linux distro is the way copying CDs and DVDs should be: easy, cheap and completely legal. And in case you are wondering, Gentle Reader, this page will not deal with the murkier world of copy protection and encryption except to mention just briefy that these technologies suck. Back to more pleasant subject and the command to rip our favourite Linux distro from its DVD to the HDD and convert it to iso:

$ dd if=/dev/dvd of=my_distro.iso bs=2048

I have rarely had any trouble with a data transfer of this type but I have been known to err on the side of caution and mount the iso and read a few files from it before burning to DVD. Having created the mount point /mnt/tmp the first of the following two commands will mount the image to be tested and the second command will unmount the image when you are finished:

# mount -o ro,loop -t iso9660 my_distro.iso /mnt/tmp
# umount /mnt/tmp

There is something a little special about that isn't there? But next to burn the iso image to a fresh DVD and the following command should do that quite nicely:

$ growisofs -dvd-compat -Z /dev/dvd=my_distro.iso

Now your Linux DVD is ready to distribute to your friends, keep as backup or install to your computer. If however you are burning your iso image to a CD rather than a DVD you would be better to use Jörg Schilling's cdrecord. This program is more than a little quirky but the results are always good and there are many, many options available to those prepared to trawl through the man pages. First issue the following command:

# cdrecord --scanbus

This gives the address 1,0,0 on my system, yours of course will be different. You will note that unless your installation of cdrecord has been modified you will need to be root for all of these commands. To then burn our iso image to CD the following syntax should suffice:

# cdrecord -v dev=1,0,0 -speed 8 driveropts=burnfree fs=32 -eject my_distro.iso

And there you have it, although all of these settings can varied according to your hardware, burning needs, available media, inclination etc. Some of these settings may also be entered in /etc/default/cdrecord to save some typing and strain on the memory. On my own system, which has a single CD drive, the settings I have used above can be set as:

#----- /etc/default/cdrecord ------------#

# The default recording device to be used by cdrecord:
CDR_DEVICE=Optiarc

# The default writing speed to be used by cdrecord:
CDR_SPEED=8

# The default fifo size while writing:
CDR_FIFOSIZE=32m

# Device name, scsi address, speed, fifo, drive specific options separated by 
# tab spaces (-1 means use the defaults, use "" if no driveropts):
Optiarc=	1,0,0	-1	-1	burnfree

The exact location of this file on your system may vary from this. This reduces the command line substantially but is not binding as any command line options that you decide to use will override these settings. Anyway all the best with your own burning and remember to keep it legal!

Making Copies of Audio Cds

Duplicating audio cds has an undeserved reputation for difficulty. I have copied many, many audio cds with the program cdrdao and more recently with cdda2wav & cdrecord with not a single frisbee or drink coaster to show for my efforts. To cdrdao first:

Using cdrdao...

A vital first step is to allow cdrdao to examine the address of your cdrom drive by running the following, on most systems this will need to be done as root:

# cdrdao scanbus

On my system this identifies the address of the single drive as 1,0,0 yours of course will be different. Next to rip the tracks to the HDD and generate the required table of contents:

# cdrdao read-cd --source-device 1,0,0 --driver generic-mmc \
                 --paranoia-mode 3 audiocd.toc 

This leaves the file data.bin and audiocd.toc in your working directory ready for burning. The next line demonstrates the required syntax for burning these files to CD:

# cdrdao write  --device 1,0,0 --driver generic-mmc \
                --buffers 128 --speed 8 audiocd.toc

If you are a little cautious you can use cdrdao simulate instead of cdrdao write and this will run a simulated burn rather than an actual burn. There is a lot of command line to remember so to make it all a little easier for the forgetful of us the following can be entered into the file /etc/cdrdao.conf:

#-- /etc/cdrdao.conf --#
write_buffers: 128
write_device: "1,0,0"
write_driver: "generic-mmc"
read_device: "1,0,0"
read_driver: "generic-mmc"
read_paranoia_mode: 3
write_speed: 8

Now these options do not need to be included in your command line, although any settings you make on the actual command line will override these options.

Using cdda2wav & cdrecord...

I have used cdrdao for many years now and I have been very happy with the results but recently I have been using a combination of cdda2wav & cdrecord. If you follow this path note that I use Jörg Schillings software rather than the Debian fork and I would recommend you do the same. First allow cdda2wav to identify your drive by running the following command, on most systems this needs to be done as root:

# cdda2wav -scanbus

This gives the address 1,0,0 on my system, yours of course will be different. Now with your audio cd in place run the following command which will interrogate a cddb server for album and track details and then rip each track as a wav file:

# cdda2wav dev=1,0,0 -vall cddb=0 -B -Owav

With that done you can now burn these files to cd with cdrecord using the device address that was previously identified with cdda2wav:

# cdrecord dev=1,0,0 -v -dao -useinfo -text *.wav

As I have mentioned previously on this page cdrecord settings can be placed in the configuration file /etc/default/cdrecord and I do just this with my own settings:

#----- /etc/default/cdrecord ------------#

# The default recording device to be used by cdrecord:
CDR_DEVICE=Optiarc

# The default writing speed to be used by cdrecord:
CDR_SPEED=8

# The default fifo size while writing:
CDR_FIFOSIZE=32m

# Device name, scsi address, speed, fifo, drive specific options separated by 
# tab spaces (-1 means use the defaults, use "" if no driveropts):
Optiarc=	1,0,0	-1	-1	burnfree

The exact location of this configuration file on your system may vary from this. This reduces the command line substantially but is not binding as any command line options that you decide to use will override these settings. Anyway all the best with your own burning and remember to keep it legal!

Making Copies of Your Movie DVDs

I have a small collection of DVD movies that I have paid a fair sum for and usually watch them from a backup copy rather than risk the expensive originals. These backup copies are made with vobcopy which also uses libdvdread (and libdvdcss as well if the DVD is encrypted). Once you have these programs assembled, Gentle Reader, the initial syntax is very easy:

$ vobcopy -m

The -m option simply tells vobcopy to "mirror" the DVD to your HDD with decryption carried out at the same time. Then change to the directory containing the movie files, you will see a directory named VIDEO_TS, and run mkisofs from this location to create the movie iso:

$ mkisofs -v -dvd-video -o ../movie_name.iso .

The final "." is important as it tells mkisofs to use the current directory contains the movie files. Finally burn your movie to DVD as normal:

$ cd ..
$ growisofs -dvd-compat -Z /dev/dvd=movie_name.iso

I should probably remind you, Gentle Reader, that you will need to substitute your own values for the movie title and iso file. And I hope you enjoy your movie!

Backing up Some Directories to DVD

I have been working for some time on a fairly basic backup system for my Linux computer which really only involves taking a copy of certain directories a few times a week. This creates a copy of my University work, web pages I am writing and the many configuration files I have spent many hours creating. To do this I use two programs: mkisofs and growisofs and I shall walk you through the process, Gentle Reader, so it is easy to understand.

To start with I give the syntax to create the iso image backup.iso of my $HOME directory in a format that can be read on Linux computers, using the Rock Ridge Interchange Protocol, and Windows computers, using the Joliet extension. I do not deal here with the Hierarchical File System (HFS) used by Macintosh although mkisofs can generate a hybrid CD using this protocol as well. Note that this is a modified form of the Rock Ridge protocol with file ownership and modes set to more useful values:

$ mkisofs -o backup.iso -r -J /home/andrew

Now say that I really don't want to include the sub-directory /home/andrew/source in this image and I also want to add a few more directories but I would like to map them to the DVD in a slightly different structure:

# mkisofs -o backup.iso -r -J \
         -x /home/andrew/source \
         -graft-points "my_files/=/home/andrew" "configuration_files/=/etc" \
         "cron_files/=/var/spool/cron/crontabs"

Now I would like to add a volume label to the DVD so that my system will identify it by a recognisable label, in this case the backup date. I will also add my own name here as the publisher of this DVD:

# mkisofs -o backup.iso -r -J -V "Backup `date +"%d %B %Y"`" \
          -x /home/andrew/source -publisher "Andrew Strong" \
          -graft-points "my_files/=/home/andrew" "configuration_files/=/etc" \
          "cron_files/=/var/spool/cron/crontabs"

The final addition to the mkisofs syntax is designed to hide the directory RR_MOVED from sight, a directory created when Rock Ridge has to move a lot of files around in deep directory structures. But in a bonus for you, Gentle Reader, I also add the growisofs command to burn the iso image to DVD in a single command:

# growisofs -dvd-compat -speed=1 -Z /dev/dvd \
          -r -J -hide-rr-moved -V "Backup `date +"%d %B %Y"`" \
          -x /home/andrew/source -publisher "Andrew Strong" \
         -graft-points "my_files/=/home/andrew" "configuration_files/=/etc" \
         "cron_files/=/var/spool/cron/crontabs"

growisofs is of course a frontend for mkisofs and thus uses the same commands. And there you have it, a backup DVD that is readable on both Linux and Windows. The many, many other options available in mkisofs I will leave you, Gentle Reader, to explore on your own. Again I wish you all the best with your burning and remember: keep it legal!

And in conclusion .....

I owe Greg Ippolito a special thanks for his page YoLinux Tutorial: Burning a CD or DVD which was very helpful in research for my own page. I would recommend this page for those who would like a more "encyclopaedic" approach to the area. Please feel free to contact me with any errors of fact that you have found on this page, any errors of opinion will probably remain uncorrected. In the meantime I am having a great time exploring Linux and the amazing command line, what about you?