Burning CDs from the command-line

ALERT! These notes are no longer maintained, and are provided as a starting point for those who wish to burn via the command-line. All users are recommended to use K3b on KDE instead.


This technote does not describe how to burn a CD/DVD on computers running MS-Windows or MacOS. For this you should consult the manuals for CD/DVD creation software that runs on those operating systems. A programmer may be able to assist.

Finally, this document only describes how to create data disks, and not music CDs or DVD video disks.

At the time of the last update of this technical note (March 2006) all ECS NetBSD workstations were Dell Optiplex GX270, GX280 and GX620 models and had at least combination drives that could write CD-RW/CD-R disks and read DVDs. If you need to write a CD from another type of computer (ie: a laptop) that doesn't have a built in CD writer the school has an Iomega USB CD-RW writer available for staff and graduate students to use.

For burning DVDs some of our GX280's and GX620's have built-in DVD writers (NEC ND-3450A or Phillips DVD8701) capable of writing to DVD+/-R, DVD+/-RW and dual layer DVD+R disks. Most of these are in staff offices, but vivian (in CO322), rise and majoribanks (in CO232) and flying-burrito-brothers (in CO238) are all in ECS labs. The school also has a portable DVD writer ( Sony DRU 510A) capable of writing single layer DVD+R, DVD-R, DVD+RW and DVD-RW disks.

Creating an ISO 9660 Image

The first step of writing files to a CD is to combine those individual files into a single file in ISO 9660 filesystem format. (If you are creating a DVD this step is optional as described in the section on growisofs below). The name "ISO 9660" comes from the International Standards Organisation's document describing the file system format.

On our NetBSD systems you can create an ISO 9660 format image file using the command mkisofs.

You can consult the manual page for a full list of options and capabilities. But if you just want to create an image which when written to a CD/DVD can be read nicely on both UNIX and Windows (though not so well on MacOS 9.x systems) the following command line will work.

mkisofs -D -l -m '#*' -m '*~' -m '*.core' -N -r -J -V "Your Disk Title" -o image.iso myfiles

In the above command line, the '-m' flags are optional and simply cause the command to omit files matching the given patterns from the image file (in the above case emacs backup and autosave files and core files). You would of course replace " Your Disk Title " by something more descriptive (maximum of 16 characters). The '-o' flag specifies the file that the ISO image will be written to.

Finally the myfiles at the end of the command line specifies the directory to be written to the CD. You can specify any directory name (or multiple directories in which case mkisofs will merge the contents of all of them into one image file).

Note however that the image will not include the actual name(s) listed on the command line. That is, if you had a directory "foo" containing subdirectories "bar" and "baz", and you run a mkisofs command specifying "foo" on the command line, the ISO9660 filesystem image produced will not contain a "foo" directory. Rather, its two subdirectories "bar" and "baz" will appear as top-level directories.

If you specifically want "foo" to appear on your disk you could specify foo's parent directory on the mkisofs command line. If you do this though you might have to prevent sibling directories of "foo" from also being included in the image (perhaps by temporarily moving directories or by using the '-m' option). Alternatively you could use the grafting features of mkisofs (described in detail in the manual page) to make a "foo" directory appear as the top level directory in the image.

Finally, a few points concerning the size of the generated image file.

Before running mkisofs you should determine how large the image file will be. The UNIX "du -h -s" command run on each of the directories that will be passed as pathnames to mkisofs will give the total size of the files in the UNIX filesystem. This will be close to the total size required by the ISO9660 image file, with any small difference being due to the different formats of the ISO 9660 and UNIX filesystems.

You can use the UNIX "df" command to ensure that there is sufficient free space on the filesystem you are writing your image to. If you are creating your image on one of our NetBSD workstations the best option is to write your image to it's /local/scratch filesystem since that is almost certain to have enough space and also has other benefits mentioned below.

You also need to ensure that the total size of the image file is less than the capacity of your disk (650MB - 700MB for a CD and approximately 4.4GB for DVD). If it is too big to fit on one disk you will have to split the data up and write several image files. The mkisofs command cannot do this for you.

And lastly, once you have finished with your image file(s) please delete them from our system to free up the disk used!

Connecting a CD/DVD Writer

If you are using one of our workstations that has a built-in CD or DVD writer you can ignore this section.

When you plug our USB CD or DVD drive in to a computer running NetBSD you should see messages similar to the following appear in an xconsole window.
umass0 at uhub1 port 2 configuration 1 interface 0
umass0: Iomega USB Zip CD, rev 1.00/1.00, addr 2
umass0: using SCSI over Bulk-Only
scsibus0 at umass0: 2 targets, 1 luns per target
scsibus0: waiting 2 seconds for devices to settle...
cd1 at scsibus0 target 1 lun 0:  SCSI0 5/cdrom removable
The various device identification and address, port and revision numbers may vary from that shown but if you don't get all of these lines (in particular, the "cdX at scsibusY..." line) then the rest of the procedure described in this document will not work. One possible cause is faulty USB hardware in the computer you are using. You could try rebooting the computer and if that doesn't work try a different one. You should also report the problem to a programmer so we can get the fault fixed.

Writing the Image

Having got a computer with a working CD or DVD device you should copy your ISO 9660 image on to a disk local to that computer. This is because the writing process needs to provide data to the drive at a minimum rate otherwise the disk will not be written correctly. If the data is written directly from a network file system (such as your home directory) this minimum rate may not be maintained and the result could be a corrupted disk. If you are using one of our NetBSD workstations the best option is to write your image to the /local/scratch filesystem of the machine with the CD or DVD writer.

Writing to a CD Using cdrecord

To write your ISO9660 filesystem image to a CD-R/-RW you use a cdrecord command like the following:
cdrecord -v dev=/dev/rcdXd /local/scratch/image.iso
(Note: the "rcdXd" in the above should be replaced by the UNIX name of the CD/DVD device you are using. If you are using the builtin drive on an ECS workstation this will typically be "rcd0d" whereas a USB drive would usually be "rcd1d". However, if another USB disk device such as a memory stick was plugged in at the time the USB CD/DVD writer was connected or if the USB CD/DVD was plugged in while the workstation was rebooting the devices may be numbered differently).

When using the USB CD-RW drive on NetBSD you may find that during its initialisation stage cdrecord reports an error and ejects the disk. If this happens, push the CD drawer closed and cdrecord should continue. It may do this several times but most often it eventually successfully writes to the disk.

If you are writing to a CD-RW disk that has been written to before you will need to blank the disk first. You can do this with the command
cdrecord -v dev=/dev/rcdXd blank=fast

The manual pages for mkisofs and cdrecord describe how you can create a multisession CD (one that has had data added to it on more than one occasion while retaining the previous data). However, I have been unable to make this work (when I last tried in Nov 2005 it crashed the workstation I was using). Hopefully this will be fixed in the future. Until then a workaround is to read the existing material from the CD to local disk, merge in the new material and generate a new ISO9660 image which can be rewritten to the same disk (after it is erased) or written to a new disk.

Writing to a DVD Using growisofs

For DVD's the growisofs command should be used instead of cdrecord. This command is part of the dvd+rw-tools package (the name is historical since it is now capable of writing DVD-R/-RW disks). Growisofs is itself also misnamed since it can now do more than just "grow" an ISO file system! Growisofs can optionally run mkisofs for you so you don't have to prepare an ISO 9660 image in advance.

The online manual page gives more information about the this command, but some examples of its use follow.
growisofs -Z /dev/rcdXd -R -J /some/files
Generate an ISO 9660 image of the directory "/some/files" and write it to a DVD, erasing any previous contents (-Z) if the disk was a DVD+RW/-RW. Include rockridge (-R) and joliet (-J) extentions on the disk.
growisofs -M /dev/rcdXd -R -J /some/files
As above, but instead of erasing any existing contents of the disk, merge (-M) the new files with them. Unlike cdrecord, growisofs does seem to be able to create multisession disks on NetBSD (although the manual page does list some caveats).
growisofs -Z /dev/rcdXd=image.iso
Write the image file image.iso to the disk instead of running mkisofs on a specified directory.

System Load While Creating Disks

As mentioned earlier in this technical note, data must be sent to a CD or DVD writer at a minimum rate otherwise the resulting disk may be corrupted. It used to be the case that in order to guarantee the required minimum rate all other activity on a computer that was writing a disk had to be suspended. Now faster computers and CD/DVD writers with larger buffer memories have minimised the occurence of the problem. Nevertheless, to be safe it is better to not excessively load your workstation while it is writing a disk. Reading email or browsing simple web sites should be fine, but running large I/O or CPU bound tasks could cause problems.