Burning a CD

Problem

You have a directory full of files on your Linux system that you would like to burn to a CD. Do you need an expensive CD burning program, or can you do it with the shell and some open source programs?

Solution

You can do it with two open source programs called mkisofs and cdrecord, and a bash script to help you keep all the options straight.

Start by putting all the files that you want to copy to CD into a directory structure. The script will take that directory, make an ISO filesystem image from those files, then burn the ISO image. All it takes is a bunch of disk space and a bit of time—but you can get up and wander while the bash script runs.

Warning

This script may not work on your system. We include it here as an example of shell scripting, not as a workable CD recording and backup mechanism.

 1 #!/usr/bin/env bash 2 # cookbook filename: cdscript 3 # cdscript - prep and burn a CD from a dir. 4 # 5 # usage: cdscript dir [ cddev ] 6 # 7 if [[ $# < 1 || $# > 2 ]] 8 then 9 echo 'usage: cdscript dir [ cddev ]' 10 exit 2 11 fi 12 13 # set the defaults 14 SRCDIR=$1 15 # your device might be "ATAPI:0,0,0" or other digits 16 CDDEV=${2:-"ATAPI:0,0,0"} 17 ISOIMAGE=/tmp/cd$$.iso 18 19 echo "building ISO image..." 20 # 21 # make the ISO fs image 22 # 23 mkisofs -A "$(cat ~/.cdAnnotation)" \ 24 -p "$(hostname)" -V "$(basename $SRCDIR)" \ 25 -r -o "$ISOIMAGE" $SRCDIR 26 STATUS=$? 27 if [ $STATUS -ne 0 ] 28 then 29 echo "Error. ISO image failed." 30 echo "Investigate then remove ...

Get bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.