Writing CD-Rs
Under FreeBSD, data on conventional hard disks is stored in the UNIX File System or UFS format. CD-ROMs and CD-Rs use a different file system, the ISO 9660 format, which is compatible with other systems. This is not a problem when you mount a CD-ROM: FreeBSD includes a read-only ISO 9660 file system. When you want to write a CD-R, however, things are a little more complicated: the medium requires you to write the entire file system at once, and since the file system is stored in a different format, you can't just copy the UFS file system. Instead, you must first create an image of the file system that you want to put on the CD-R, and then you copy it. We'll look at these steps in more detail below.
Creating an ISO-9660 image
The first step is to create the ISO 9660 file system image, frequently simply called an ISO image. There are a number of ports available in the Ports Collection; here we'll look at mkisofs, which is part of the cdrtools port. Installation isn't quite as straightforward as you might expect: you need a special fag to install mkisofs:
# cd /usr/ports/sysutils/cdrtools # make install -DMKISOFS
mkisofs has a bewildering number of parameters. Here are the important ones:
- The -A option specifies the application ID, a text string written to the header of the file system to describe the "application" on the image. It can be up to 128 characters long.
- Use -b if you want to be able to boot from the CD, such as a FreeBSD bootable CD. In the case of FreeBSD, use the 2.88 MB image fbppies/boot.fp which is built as part of the release process. Note that this file must be in one of the directories included in the image, and the name is relative to the root directory of the CD.
- The -f option tells mkisofs to follow symbolic links. If you don't specify this option and you have symbolic links in the directory from which you create the image, the resultant CD-ROM image will contain only a symbolic link instead of the file itself. If the file to which the symbolic link points is below the top-level (root) directory, this is the preferred way to do things, because it saves space, but if it points outside the CD-ROM, the file will not appear on the CD-ROM at all. Use this option if you have symbolic links to files outside the directory that you're using for the root of the CD-ROM file system.
- The -J option makes the CD compatible with Microsoft's Joliet format. You don't need it for FreeBSD, but it doesn't cost much, so it's a good idea to include it if there's a chance the CD will be used in a Microsoft environment.
- Use the -o option to specify the name of the resultant ISO image. This image is the size of the resultant CD, so it could be up to 700 MB.
- The -p option specifies the preparer ID, another ISO 9660 header field to specify who made the CD-ROM.
- The -r option specifies the Rock Ridge Extensions that are used to store UNIX file names. It makes a number of assumptions about permissions and owners; see the man page for details. It takes no parameters.
- The –T option tells mkisofs to include a translation file TRANS.TBL in each directory for use by systems that don't support the Rock Ridge extensions. For each file name in the directory, TRANS.TBL contains a Microsoft-compatible name (up to eight characters, a period (.) and up to three more characters). The names bear a slight resemblance to the original names.
- If you don't like the name TRANS.TBL, you can specify a different name with the -table-name option, which implies -T. For example, if you write -table-name.MAP you will generate names that won't show up with a normal ls command.
- The -V option specifies the volume ID for the file system. This will normally be more specific than the application ID; for example, each CD in a set of CDs might have the same application ID and a different volume ID.
- The final parameters are the names of the directories that will be included in the image. You can specify multiple directories. In each case, the entire directory hierarchy will be included.
This is a lot of stuff to type in every time. It's easier to write a Make file and use make:
APPLID = "Dummy application " BOOT = #To make it bootable, put in something like this: #Note that the -b option is there as well #BOOT = "-b floppies/boot.flp " ISO = /var/tmp/isoimage PREPARER = "me " VOLID = "Volume 0000 " DIR = . cdrom: mkisofs -A ${APPLID} ${BOOT} -J -o ${ISO} -f \ -p ${PREPARER} -r -T -V ${VOLID} ${DIR}
For example, to make a bootable CD-R of the FreeBSD release, you would first perform the make world and make release. Assuming that the release directory is /home/release, you will find the directory trees for the first two CD-ROMs in /home/re-lease/R/cdrom/disc1 and /home/release/R/cdrom/disc2. You could do this:
# make cdrom DIR=/home/release/R/cdrom/disc1 mkisofs -A "Dummy application " -J -o ../iso -table-name .MAP -p "Greg Lehey " -r –T -V "Volume 000" 6.40% done, estimate finish Sun Aug 27 13:34:54 2000 12.79% done, estimate finish Sun Aug 27 13:35:02 2000 19.19% done, estimate finish Sun Aug 27 13:35:05 2000 25.57% done, estimate finish Sun Aug 27 13:35:10 2000 31.97% done, estimate finish Sun Aug 27 13:35:10 2000 38.36% done, estimate finish Sun Aug 27 13:35:10 2000 44.75% done, estimate finish Sun Aug 27 13:35:10 2000 51.15% done, estimate finish Sun Aug 27 13:35:12 2000 57.54% done, estimate finish Sun Aug 27 13:35:12 2000 63.94% done, estimate finish Sun Aug 27 13:35:12 2000 70.34% done, estimate finish Sun Aug 27 13:35:11 2000 76.72% done, estimate finish Sun Aug 27 13:35:13 2000 83.12% done, estimate finish Sun Aug 27 13:35:12 2000 89.52% done, estimate finish Sun Aug 27 13:35:13 2000 95.90% done, estimate finish Sun Aug 27 13:35:13 2000 Total translation table size: 35119 Total rockridge attributes bytes: 59724 Total directory bytes: 104448 Path table size(bytes): 256 Max brk space used 86224 78211 extents written (152 Mb)
The progress reports are rather boring nowadays, considering that the whole process only takes a couple of minutes, but the summary information at the bottom can be of interest.
Testing the CD-R
So now you have an ISO image. How do you know it's correct? It's just a single file, and it could have just about anything on it. You can burn a CD, of course, but if it's junk, you have another coaster. If you're not sure, it's better to look inside first. You can do that by using it as the basis for an md vnode device.
The md driver creates a number of different kinds of pseudo-device. See the man page md (4) for more details. We use the vnode device, a special file that refers to file system files. Support for md is included in the GENERIC kernel, but if you've built a kernel without the md driver, you can load it as a kld. If you're not sure, try loading the kld anyway. Then you associate a vnode device with the ISO image iso-image using the program mdconfig:
# kldload md load the kld module if necessary kldload: can't load md: File exists already loaded or in the kernel # mdconfig -a -t vnode -f iso-image configure the device md0 this is the name assigned # mount -t cd9660 /dev/md0 /mnt mount it
After this, you will be able to access the image at /mnt as a normal file system. Don't forget to un mount and un configure the file when you're finished:
# umount /mnt # mdconfig -d -u 0
Older releases of FreeBSD used the vn driver, which used different syntax.