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. Three such examples are in place now:
- Making Copies of Your Favourite Linux Distro Using growisofs, dd and cdrecord to produce perfect copies of your favourite Linux distro to CD or DVD.
- Making Copies of Audio Cds Using cdrdao to produce perfect copies of your audio CDs.
- Backing up Some Directories to DVD Backing up a few directories to DVD using mkisofs to create the iso image and growisofs to burn to DVD.
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 1001,0,0 on my system, yours of course will be different. You will note that unless your copy 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=1001,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=HL-DT-ST # 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): HL-DT-ST= 1001,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 with not a single frisbee or drink coaster to show for my efforts. I have developed a rather conservative method to accomplish this that may not suit all people but it has served me well. First issue the following command:
$ cdrdao scanbus
On my system this identifies the single drive as ATA: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 ATA: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 ATA: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: "ATA:1,0,0" write_driver: "generic-mmc" read_device: "ATA: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. Anyway all the best with your own burning and remember to keep it legal!
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?