(Modified 2010 Feb 12)
Burning CDs and DVDs
There are graphical interfaces for CD-burning, e.g., nautilus, xcdroast, k3b. However, I knew that CD-burning requires only two steps, so I wanted to learn how to burn CDs from the command line. A couple of good starting points are IBM, YoLinux, and ArchLinux. You could, of course, try man mkisofs, man cdrecord, or man growisofs.
Making an ISO file
The first step is to make an ISO image. The (over)simplified way to think about an ISO is that the files are packaged a certain way that is amenable to creating a CD. In actuality an ISO is a true file system.
Suppose we want to burn directories local_dir_1 and local_dir_2 to cd_dir1 and cd_dir2, respectively. The syntax is:
mkisofs --graft-points -o test.iso -J -R -v -V test_disk cd_dir1/=local_dir_1 cd_dir2/=local_dir_2/
where:
--graft-points means that you'd like to make subdirectories on the CD
-o test.iso specifies the name of the ISO image
-J specifies Joliet naming, for use with Windows
(For some long filenames, the -joliet-long flag may be required.)
-R specifies Rock Ridge naming (I don't remember what this is for, except that it was useful)
-v verbose
-V volume ID, seen in Windows
To illustrate that the ISO is an actual file system, and to test the ISO, you'll need to mount it:
mkdir testmount mount -o loop test.iso testmount
The -o loop flag is needed to mount a file as a block device. (You may need the flag -t iso9660 also, although I didn't.) You may need to be root or use sudo in order to mount. Once you've done this, you should be able to cd in this testmount/ directory.
Setting up cdrecord
If you're burning a DVD, skip ahead to "Burning DVDs."
For some reason, the command cdrecord by default can only be executed by root. To change this, I typed, as root:
chmod u+s /usr/bin/cdrecord
I don't know what the +s flag means.
Before we can actually burn the CD, we need to figure out the address of the burner on the bus. To find out this address, type:
cdrecord dev=ATAPI -scanbus
I have an ATAPI CD-burner; I don't know what that means exactly. If you have an ATAPI CD-burner and don't include the dev=ATAPI flag, things don't work. The relevant error message if I didn't add this specification was:
cdrecord: No such file or directory. Cannot open '/dev/sg*'. Cannot open SCSI driver.
NOTE: Using Ubuntu, ATAPI isn't the correct dev flag. The correct one is /dev/scd0
I only knew that by inserting a working CD and typing df (to get a list of mounted disks).
Upon use of the ATAPI flag, the desired line of output from this bus-scan looks like:
0,0,0 0) 'RICOH ' 'DVD/CDRW MP9060 ' '1.30' Removable CD-ROM
Burning the CD
We can go through a dry run, doing everything except burning the CD. The syntax is:
cdrecord -v -eject speed=4 dev=ATAPI:0,0,0 -dummy test.iso
where:
-v specifies verbose output
-eject ejects the disk after completion
speed=4 specifies the write-speed (Theoretically, I can burn at 6X, which superstitiously I burn at the second-highest rate)
dev=ATAPI:0,0,0 is the bus address that I got from the scanbus step
-dummy specifies a dry run
test.iso is the ISO image that I created with mkisofs
To actually burn the CD, we simply remove the -dummy flag, i.e.:
cdrecord -v -eject speed=4 dev=ATAPI:0,0,0 test.iso
If you get the following error:
Cannot allocate memory. Cannot get SCSI I/O buffer
...then you may need to be root to burn CDs.
You can: 1) log in as root, 2) use sudo, or 3) as described above, chmod for cdrecord.
Reading the CD/Mounting/Unmounting
In case you need to explicitly mount/unmount a CD, this is done using
mount /mnt/cdrom/
and
umount /mnt/cdrom/
respectively.
On some systems, CDs will automatically mount. If the CD won't eject, it probably means you need to explicitly unmount it first.
Erasing CDRWs
To erase a CDRW, there is a blank flag:
cdrecord dev=ATAPI:0,0,0 -v -eject speed=2 blank=all
There is a blank=fast flag also, but it doesn't erase the data. I'm not sure how that affects things.
Burning DVDs
The command I'm using to burn a DVD is growisofs. The step where you make the ISO is the same, but specifying the burner is a little different.
You'll need to find the device name in /dev. (Using the mountpoint in /mnt didn't work for me.) If you're not sure what the DVD-burner is called (I wasn't), check the diagnostic message, using the command dmesg. (dmesg is useful for a lot of other tasks too, such as mounting USB devices.)
When I type dmesg and search for 'DVD', I see:
scsi 1:0:0:0: CD-ROM _NEC DVD_RW ND-3520A 1.04 PQ: 0 ANSI: 5 sr0: scsi3-mmc drive: 48x/48x writer cd/rw xa/form2 cdda tray
The device name is thus /dev/sr0.
Now, to burn the DVD, type:
growisofs -Z /dev/sr0=test.iso
where -Z starts the burn at the beginning of the DVD at the device whose name follows.
This page is Lynx-enhanced