Writing CD-Rs In this chapter: ISO-9660 image In this chapter: ISO-9660 image Under FreeBSD, data on conventional hard disks is stored in the UNIX File System or UFS format.. This is not
Trang 1Writing CD-Rs
In this chapter:
ISO-9660 image
In this chapter:
ISO-9660 image
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 flag to install mkisofs:
# cd /usr/ports/sysutils/cdrtools
# make install -DMKISOFS
mkisofs has a bewildering number of parameters Here are the important ones:
• The-Aoption specifies the application ID, a text string written to the header of the
Trang 2• Use-bif 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 floppies/boot.flp 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-foption 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-Joption 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-ooption 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 -poption specifies the preparer ID, another ISO 9660 header field to specify
who made the CD-ROM
• The-roption 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-Toption 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 MAPyou 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
burncd.mm,v v4.13 (2003/04/02 06:46:59)
Trang 3This is a lot of stuff to type in every time It’s easier to write a Makefile 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"
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 0000"
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.
Trang 4without 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
# 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 unmount and unconfigure the file when you’re finished:
# umount /mnt
# mdconfig -d -u 0
Older releases of FreeBSD used the vn driver, which used different syntax.
Burning the CD-R
Once you have created and tested an ISO image, you can copy it to CD-R For SCSI
burners, you use cdrecord; ATA (IDE) CD-R burners you use burncd In the following
sections we’ll look at both programs
Burning a CD-R on an ATA burner
To burn a CD-R in an ATA (or IDE) burner, use burncd, which is part of the base system Typically you’ll only have one CD-R burner on the system, so it will be called /dev/acd0 You’ll have something like this in your dmesg output:
acd0: CD-RW <RWD RW4224> at ata1-slave BIOSPIO
burncd has both flags and commands For our purposes, the most important flags are:
• The-f device option specifies the device to use for the burning process.
• The-moption tells burncd to close the disk in multisession mode.
• The-qoption tells burncd to be quiet and not to print progress messages In fact,
it’s not very verbose anyway
• The -s speed option specifies the speed of the burner device It defaults to 1, so
you’ll save a lot of time using this
• The-toption specifies a test write: burncd does not actually write on the medium.
• The-v(verbose) option prints a few extra progress messages
burncd.mm,v v4.13 (2003/04/02 06:46:59)
Trang 5The most important commands for writing ISO 9660 CD-ROMs are:
• data ormode1write data tracks, also known as mode1 tracks, for the image files
named on the command line
• fixatefixates the medium by generating the table of contents This should be the
last command to burncd.
If burncd doesn’t recognize a command, it assumes it’s a file name If it does, it assumes
it isn’t a file name This can be confusing: there are other commands not mentioned in the list above, for exampleraw If you have an ISO file called raw, you’ll have to rename
it before you can burn it with burncd.
Before you start, you should decide on the recording speed If your machine is fast enough, use the rated recording speed In the case of the example machine, that’s an 8x speed (i.e it records at eight times the speed at which a normal audio CD is played) Before you do this, though, you should make sure that your system can keep a sufficient data rate so that there is always data available to transfer to the CD-R If it can’t keep up,
you’ll get an underrun, a gap in the data, and your CD-R is worthless (a coaster).
To make sure you don’t make coasters, you should do a test run The system goes through all the motions, but it doesn’t actually write anything to the CD-R blank Nevertheless, it tests all aspects of the burn, so you must have a valid CD-R blank in the
drive, otherwise the attempt will fail To test burn an image called iso, enter:
# burncd -f /dev/acd0c -t -v -s 8 data iso fixate
adding type 0x08 file iso size 184576 KB 92288 blocks
next writeable LBA 0
addr = 0 size = 189005824 blocks = 92288
writing from file iso size 184576 KB
written this track 6880 KB (3%) total 6880 KB
At this point, burncd overwrites the line with progress indications until it is finished.
Finally, you see:
written this track 184576 KB (100%) total 184576 KB
fixating CD, please wait
burncd: ioctl(CDRIOCFIXATE): Input/output error
This last line appears a little alarming It’s not really serious, though: the CD has not really been written, so it’s not possible to read from it A number of CD-R drives return error conditions under these circumstances
If everything was OK in the test run, you can repeat the command without the-tflag:
# burncd -f /dev/acd0c -v -s 8 data iso fixate
The output is identical, but this time you should not get the error message
Trang 6Burning a CD-R on a SCSI burner
If you have a SCSI burner, use cdrecord, which is part of the cdrtools port we installed
on page 243 cdrecord has a rather strange habit of not using device names: instead, it
accesses the device directly by its SCSI parameters (bus, unit and LUN) You can get
these parameters from the dmesg output in /var/run/dmesg.boot, but there’s an easier
way:
# cdrecord -scanbus
Cdrecord 1.9 (i386-unknown-freebsd4.1) Copyright (C) 1995-2000 Jörg Schilling Using libscg version ’schily-0.1’
scsibus0:
0,0,0 0) ’MATSHITA’ ’CD-R CW-7503 ’ ’1.06’ Removable CD-ROM
cdrecord: Warning: controller returns zero sized CD capabilities page.
cdrecord: Warning: controller returns wrong size for CD capabilities page.
cdrecord: Warning: controller returns wrong page 0 for CD capabilities page (2A).
0,1,0 1) ’TEAC ’ ’CD-ROM CD-532S ’ ’1.0A’ Removable CD-ROM
0,2,0 2) *
0,3,0 3) *
0,4,0 4) ’SONY ’ ’SDT-10000 ’ ’0101’ Removable Tape
0,5,0 5) *
0,6,0 6) *
0,7,0 7) *
0,8,0 8) ’QUANTUM ’ ’QM318000TD-SW ’ ’N491’ Disk
This output doesn’t tell you exactly which devices are CD-Rs, and it also doesn’t look at any except the first SCSI bus Alternatively, you can use the standard system utility
camcontrol:
# camcontrol devlist
<MATSHITA CD-R CW-7503 1.06> at scbus0 target 0 lun 0 (pass0,cd0)
<TEAC CD-ROM CD-532S 1.0A> at scbus0 target 1 lun 0 (pass1,cd1)
<SONY SDT-10000 0101> at scbus0 target 4 lun 0 (sa0,pass2)
<QUANTUM QM318000TD-SW N491> at scbus0 target 8 lun 0 (pass3,da0)
<EXABYTE EXB-8505SMBANSH2 0793> at scbus1 target 1 lun 0 (sa1,pass4)
<Quantum DLT4000 CC1E> at scbus1 target 3 lun 0 (sa2,pass5)
<AIWA GD-8000 0119> at scbus1 target 4 lun 0 (sa3,pass6)
<NRC MBR-7 110> at scbus1 target 6 lun 0 (pass7,cd2)
<NRC MBR-7 110> at scbus1 target 6 lun 1 (pass8,cd3)
<NRC MBR-7 110> at scbus1 target 6 lun 2 (pass9,cd4)
<NRC MBR-7 110> at scbus1 target 6 lun 3 (pass10,cd5)
<NRC MBR-7 110> at scbus1 target 6 lun 4 (pass11,cd6)
<NRC MBR-7 110> at scbus1 target 6 lun 5 (pass12,cd7)
<NRC MBR-7 110> at scbus1 target 6 lun 6 (pass13,cd8)
Either way, you need to recognize the CD-R device, which in this case is relatively easy: it’s the Matsushita CW-7503 (‘‘MATSHITA’’) at the very beginning of each list cdrecord
refers to this device as0,0,0(bus 0, target 0, LUN 0)
The next thing to look at is the recording speed If your machine is fast enough, use the rated recording speed In the case of the example machine, that’s an 8x speed (i.e it records at 8 times the speed at which a normal audio CD is played) Before you do this, though, you should make sure that your system can keep a sufficient data rate so that there is always data available when to go on the CD If you can’t keep up, you’ll get an
underrun, a gap in the data, and your CD-R is worthless (a coaster).
burncd.mm,v v4.13 (2003/04/02 06:46:59)
Trang 7To make sure you don’t make coasters, you should do a dummy run The system goes through all the motions, but it doesn’t actually write anything to the CD-R blank Nevertheless, it tests all aspects of the burn, so you must have a valid CD-R blank in the
drive, otherwise the attempt will fail To burn an image called iso, enter:
# cdrecord -dummy -v dev=0,0,0 -speed=8 iso
Cdrecord 1.9 (i386-unknown-freebsd5.0) Copyright (C) 1995-2000 Jörg Schilling TOC Type: 1 = CD-ROM
scsidev: ’0,0,0’
scsibus: 0 target: 0 lun: 0
Using libscg version ’schily-0.1’
atapi: 0
Device type : Removable CD-ROM
Version : 2
Response Format: 2
Capabilities : SYNC LINKED
Vendor_info : ’MATSHITA’
Identifikation : ’CD-R CW-7503 ’
Revision : ’1.06’
Device seems to be: Generic mmc CD-R.
Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
Driver flags : SWABAUDIO
FIFO size : 4194304 = 4096 KB
Track 01: data 152 MB
Total size: 175 MB (17:22.84) = 78213 sectors
Lout start: 175 MB (17:24/63) = 78213 sectors
Current Secsize: 2048
ATIP info from disk:
Indicated writing power: 5
Is not unrestricted
Is not erasable
ATIP start of lead in: -11080 (97:34/20)
ATIP start of lead out: 335100 (74:30/00)
Disk type: Long strategy type (Cyanine, AZO or similar)
Manuf index: 11
Manufacturer: Mitsubishi Chemical Corporation
Blocks total: 335100 Blocks current: 335100 Blocks remaining: 256887
RBlocks total: 342460 RBlocks current: 342460 RBlocks remaining: 264247
Starting to write CD/DVD at speed 8 in dummy mode for single session.
Last chance to quit, starting dummy write in 1 seconds.
Waiting for reader process to fill input buffer input buffer ready.
Starting new track at sector: 0
Track 01: 0 of 152 MB written (fifo 100%).
At this point, cdrecord overwrites the last line with progress indications until it is finished If you’re watching, keep an eye on the fifo information at the end of the line.
This gives you an idea how well the system is keeping up with the burner If the utilization drops to 0, you will get an underrun, and the blank would have become a coaster if this were for real
Finally, you see:
Track 01: 152 of 152 MB written (fifo 100%).
Track 01: Total bytes read/written: 160176128/160176128 (78211 sectors).
Writing time: 136.918s
Fixating
WARNING: Some drives don’t like fixation in dummy mode.
Fixating time: 35.963s
cdrecord: fifo had 2523 puts and 2523 gets.
Trang 8The summary information at the end shows that at some point the fifo dropped below 100% full, but this is far from being a problem If, on the other hand, there was a lot of disk activity at the same time, you might find the fifo level dropping much lower
When you’re sure that you won’t hav e any problems, you can do the real thing: just repeat the command without the-dummyoption The output looks almost identical
Copying CD-ROMs
Frequently you’ll want to make a verbatim copy of another CD There are copyright implications here, of course, but many CD-ROMs are not restricted In particular, you may make copies of FreeBSD CD-ROMs for your personal use
CD-ROMs are already in ISO format, of course, so to get a file iso, as in the examples above, you could just perform a literal copy with dd:
# dd if=/dev/cd0c of=iso bs=128k
Thebs=128ktells dd to copy in blocks of 128 kB It’s not strictly necessary, but if you
omit it, it will perform a separate transfer for every sector, and on a slow machine it can
be much less efficient
There’s an even easier way, though, if you have two CD-ROM drives: you can frequently copy directly from one drive to the other, without storing on disk at all To do this, of course, you need to be very sure that your CD-ROM drive is fast enough In particular, if
it spins down during the copy, you will almost certainly have underruns and a useless copy Be very sure to do a dummy run first Let’s assume that your second CD-ROM
drive is /dev/cd1c (a SCSI drive) For IDE drives, write:
# burncd -f /dev/acd0c -t -v -s 8 data /dev/cd1c fixate
In this example, the -f option indicates that /dev/acd0c is the (IDE) CD-R burner /dev/cd1c is the (SCSI) CD-ROM drive with the original CD-ROM You don’t need to mount /dev/cd1c, since it’s being accessed as raw data, not a file system.
When you’re sure this will work, remove the-tflag and repeat
For SCSI, enter
# cdrecord -dummy -v dev=0,0,0 -speed=8 /dev/cd1c
When it completes satisfactorily, remove the-dummyand repeat
burncd.mm,v v4.13 (2003/04/02 06:46:59)