Contributed by Mike Meyer <mwm@mired.org>, April 2001.
CDs have a number of features that differentiate them from convential disks. Initially, they weren't writable by the user. They are designed so they can be read continuously without delays to move the head between tracks. They are also much easier to transport between system than similar sized media was at the time.
CDs do have tracks, but by this they mean a section of data to be read continuously, not a physical property of the disk. To produce a CD on FreeBSD, you prepare the data files that are going to make up the tracks on the CD, then write the tracks to the CD.
The ISO 9660 file system was designed to deal with these differences. It unfortunately codifies file system limits that were common then. Fortunately, it provides an extension mechanism that allows properly written CDs to exceed those limits while still working with systems that do not support those extensions.
The mkisofs program is used to produce a data file containing an ISO 9660 file system. It has options that support various extensions, and is described below. You can install it with the /usr/ports/sysutils/mkisofs port.
The tool to use to burn the CD depend on whether your CD burner is ATAPI or something else. ATAPI CD burners use the burncd program that is part of the base system. SCSI and USB CD burners should use the cdrecord from the /usr/ports/sysutils/cdrecord port.
mkisofs produces an ISO 9660 file system that is an image of a directory tree in the Unix file system name space. The simplest usage is:
# mkisofs -o imagefile.iso /path/to/tree
This command will create an imagefile containing an ISO 9660 file system that is a copy of the tree at /path/to/tree. In the process, it will map the file names to names that fit the limitations of the standard ISO 9660 file system, and will exclude files that have names uncharacteristic of ISO file systems. Read mkisofs(8) for details of this process, and options that can be used to control it.
A number of options are available to overcome those restrictions. In particular, -R will enable the Rock Ridge extensions common to Unix systems, -J causes Joliet extenions used by Microsoft systems, and -hfs can be used to create HFS file systems used by Macs. Read mkisofs(8) for more information on the last two.
For CD's that are going to be used only on FreeBSD systems, -U can be used to disable all filename restrictions. When used with -R, it produced a file system image that is identical to the FreeBSD tree you started from, though it may violate the ISO 9660 standard in a number of ways.
The last option of general use is -b. This is used to specify the location of the boot image in producing a "El Torito" bootable CD. This option takes an argument, which is the path to a boot image from the top of the tree being written to the CD. So, given that /tmp/myboot holds a bootable FreeBSD system with the boot image in /tmp/myboot/boot/cdboot, you could produce the image of an ISO 9660 file system in /tmp/bootable.iso like so:
# mkisofs -U -R -b boot/cdboot -o /tmp/bootable.iso /tmp/myboot
Having done that, if you have vn configured in your kernel, you can mount the file system by doing:
# vnconfig -e vn0c /tmp/bootable.iso # mount -t cd9660 /dev/vn0c /mnt
At which point you can verify that /mnt and /tmp/myboot are identical.
There are a large number of other options you can use with mkisofs to fine tune its behavior. See mkisofs(8) for details.
If you have an ATAPI CD burner, you can use the burncd command to burn an ISO image onto a CD. burncd is part of the base system, installed as /usr/sbin/burncd. Usage is very simple, as it does not have a lot of options:
# burncd -f cddevice data imagefile.iso fixate
Will burn a copy of imagefile.iso on cddevice. The default device is /dev/acd0. See burncd(8) for options like setting the write speed, ejecting the floppy, and writing audio data.
If you do not have an ATAPI CD burner, you will have to use cdrecord to burn your CDs. cdrecord is not part of the base system; you must install it from either the port at /usr/ports/sysutils/cdrecord or the appropriate package. Changes to the base system can cause binary versions of this program to fail, possibly resulting in a "coaster". You should therefore either upgrade the port when you upgrade your system, or if you are tracking -stable, upgrade the port when a new version becomes available.
While cdrecord has many options, basic usage is even simpler than burncd. Burning an ISO 9660 image is done by:
# cdrecord dev=device imagefile.iso
The tricky part of using cdrecord is finding the dev to use. To find the proper setting, use the -scanbus flag of cdrecord, which might produce results like this:
# cdrecord -scanbus Cdrecord 1.9 (i386-unknown-freebsd4.2) Copyright (C) 1995-2000 Jörg Schilling Using libscg version 'schily-0.1' scsibus0: 0,0,0 0) 'SEAGATE ' 'ST39236LW ' '0004' Disk 0,1,0 1) 'SEAGATE ' 'ST39173W ' '5958' Disk 0,2,0 2) * 0,3,0 3) 'iomega ' 'jaz 1GB ' 'J.86' Removable Disk 0,4,0 4) 'NEC ' 'CD-ROM DRIVE:466' '1.26' Removable CD-ROM 0,5,0 5) * 0,6,0 6) * 0,7,0 7) * scsibus1: 1,0,0 100) * 1,1,0 101) * 1,2,0 102) * 1,3,0 103) * 1,4,0 104) * 1,5,0 105) 'YAMAHA ' 'CRW4260 ' '1.0q' Removable CD-ROM 1,6,0 106) 'ARTEC ' 'AM12S ' '1.06' Scanner 1,7,0 107) *
This lists the approriate dev value for the devices on the list. Locate your CD burner, and use the three numbers separated by commas as the value for dev. In this case, the CRW device is 1,5,0, so the appriate input would be dev=1,5,0. There are easier ways to specify this value; see the cdrecord(1) for details. That is also the place to look for information on writing audio tracks, controlling the speed, and other things.