The FreeBSD Diary |
![]() |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
|
cdrecord - writing your own CDs
14 December 2000
|
|
While I was at BSDCon 2000, I was able to make a number of purchases. These were wholly/partly funded by donations and from ad revenue. One of the items was a Plextor CD-RW internal SCSI drive. I chose SCSI because of advice I was given regarding SCSI reliability with respect to CDRW drives. I chose Plextor because of the recommendations of others. Plextor has also donated several drives to the cdrecord author (see here for details), including the drive model I bought. That's a good marketing move by Plextor. It ensures the author can test and work with their hardware, thereby ensuring the software works well with that drive. NOTE: In this article, I specify the speed which should be used to write to the CD. You should adjust that value to suit your CD drive. The sharp eyed amongst you may notice that the device used in this article differs from that used in the cdrecord - writing multiple sessions article. That's not magic. And it's not a mistake. When I wrote this article, I had two SCSI cards in the box. I've since returned one to it's owner and put the CDRW on the same card as the two SCSI drives. If you are using an IDE CD-RW, you may find Burning CDs on an IDE CD-RW helpful. |
|
cdrecord resources
|
|
The home page for cdrecord is The FAQ and How-To are at: |
|
Installing
|
|
I have the entire ports tree. So it was easy. cdrecord is now part of sysutils/cdrtools. When I first wrote this article, it was in sysutils/cdrecord. To install: cd /usr/ports/sysutils/cdrtools make install You will also need mkisofs (as in Make ISO File System) for creating an ISO image. It is also in sysutils/cdrtools. In previous times, it was found in sysutils/mkisofs. |
|
Kernel suggestions
|
The notes for FreeBSD users (see above link) suggest that you include the
following options in your kernel:
options P1003_1B #Posix P1003_1B real-time extensions options _KPOSIX_PRIORITY_SCHEDULING # # The above two POSIX options were already in my kernel. # I added the following for cdrecord. # options _KPOSIX_VERSION=199309L See Building and Installing a Custom Kernel in the FreeBSD Handbook for more information on modifying your kernel. |
|
Know your CD drive
|
In order to use cdrecord, you need to know where your CD drive is installed.
Here's an extract from dmesg on my box:
cd0 at ahc0 bus 0 target 5 lun 0 cd0: <PLEXTOR CD-R PX-W124TS 1.05> Removable CD-ROM SCSI-2 device cd0: 10.000MB/s transfers (10.000MHz, offset 8) cd0: cd present [332860 x 2048 byte records] cdrecord needs the bus, target, and lun values (in the above case, that's 0,5,0). But beware, cdrecord did not recognize the above. Witness the following failure (I'll explain what I was doing in the next section):
That was odd. So I took their suggestion and tried the scanbus...
Ahah! I should be using 1,5,0, not 0,5,0. In the hopes that the following may be helpful to someone, here are the drives as listed in the above output:
|
|
Blanking a rewriteable CD
|
| In this section, I will blank out a rewritable CD. This is a CD which can be
written to many times. It is different from a CDR which can be written to only once.
It takes longer to write a rewritable CD than it does to write a single-write CD. But first, I tried a dummy session, which would then eject the tray at the end: # cdrecord -dummy -eject blank=all dev=1,5,0 And presto, whiz-bang, the CD was ejected! Woo hoo! My next task as to actually blank that CD out. You don't have to do this, but I
wanted to. Warning: blanking all of a CD takes time. This one took about 20
minutes (remember you may want to should adjust
That took about 10 minutes or so. You can see where it reloaded the media. That's when it ejected the tray and pulled it back in. Be careful not to block the CD tray (i.e. keep your coffee cup away from the tray!). |
|
Creating an image
|
In order to write data to a CD, you first need to create an ISO image. This can
be done with mkisofs. In my example, we'll work from the /home/recording
directory. In this directory, I created a subdirectory called files. Here is
what it contains:
# ls -l files total 5280 -rw-r--r-- 1 root wheel 2174400 Dec 12 10:56 freebsddiary.tif -rw-r--r-- 1 root wheel 2239494 Dec 12 10:57 freshports.tgz -rw-r--r-- 1 root wheel 956533 Dec 12 10:56 mycvs.tgz From these files, I will create an ISO image: # mkisofs -J -L -R -o cdimage.raw files Total translation table size: 0 Total rockridge attributes bytes: 471 Total directory bytes: 0 Path table size(bytes): 10 Max brk space used a164 2649 extents written (5 Mb) Thanks to mikem for helping me with the following options. I use these on each CD I write. Note: if you don't use the -J option, you may have problems if you use the CD under Windows (I know, my first CDR didn't use this option).
|
|
Things I saw but didn't worry about
|
In other testing, I used some long file names. I had installed samba on my box and used that to copy files from my NT box onto the
box containing my CDRW. Then I started to make images for burning a backup CD.
That's when I encountered messages like this:
$ mkisofs -J -L -R -o racing.raw racing/ Using KARAP000 for racing/db/Karapoti (Karapoti2000) Using KARAP001 for racing/db/Karapoti2000 (Karapoti98) At first I was worried. I thought cdrecord was converting long file names to short file names OUCH! But then I mounted the ISO image and inspected the files. Everything appeared normal. Good news! I started reading man mkisofs where I discovered translation tables. When long file or directory names are used, the ISO image also contains short names (as in DOS names which allow only 8 characters before the . and 3 characters after it). I now believe the above messages are just notification of the short file names cdrecord will use. |
|
Testing the CD image
|
The easiest way to test an image is to mount it. And oddly enough, I wrote about
mounting an ISO image more than two months ago. Here's
how to do it:vnconfig /dev/vn0c ./cdimage.raw mount -t cd9660 /dev/vn0c /mnt Now you can list the contents of the image from /mnt: # ls -lR /mnt total 5244 -rw-r--r-- 1 root wheel 2174400 Dec 12 10:56 freebsddiary.tif -rw-r--r-- 1 root wheel 2239494 Dec 12 10:57 freshports.tgz -rw-r--r-- 1 root wheel 956533 Dec 12 10:56 mycvs.tgz As you can see, this is exactly the same as what we had originally. I guess you could also do a diff, but I think that's of little use here. It's a direct disk to disk copy. But I did one anyway. I don't recommend you do it: # diff /mnt/ files/ # Remember to unmount the ISO image: umount /mnt vnconfig -u /dev/vn0c |
|
Burning the CDRW
|
| This process will allow you to burn one session on a CD. If you later wish to
add additional data, you need a multi-session CD. See cdrecord
- writing multiple sessions for that information. For this exercise, I'm going to
use a rewriteable CD. That is why I'm using speed=4. Now it's time
to burn the image. This is the command I used (remember you may want to should
adjust
The above command took about 20 seconds. Now let's have a look at the results: # mount /cdrom # ls -l /cdrom total 5244 -rw-r--r-- 1 root wheel 2174400 Dec 12 10:56 freebsddiary.tif -rw-r--r-- 1 root wheel 2239494 Dec 12 10:57 freshports.tgz -rw-r--r-- 1 root wheel 956533 Dec 12 10:56 mycvs.tgz Well, there ya go! That's the results of the burn. And just to make sure it's correct: mount /cdrom diff /cdrom files/ umount /cdrom No differences! And that's a good thing. Note that the above mount method relies on the following entry in /etc/fstab: /dev/cd0a /cdrom cd9660 ro,noauto 0 0 Without such an entry, you can mount your cdrom with this command: mount -t cd9660 -o ro /dev/cd0a /cdrom But if you see this error: cd9660: Device not configured ...the first thing to check is that there is a disk in the drive and that the tray has not been ejected. This got me! |
|
Burning the first CDR
|
| This process will allow you to burn one session on a CDR. If you later wish to
add additional data, you need a multi-session CD. See cdrecord
- writing multiple sessions for that information. After trying a CDRW, it was time
to burn a CD. If I fail with this, I'll have a coaster (for those unfamiliar with
the term, a coaster is something upon which you place your drink to avoid staining fine
furniture). Notice that I'm now using speed=12 (remember you may want to
should adjust
And that worked just fine! I did a diff: mount /cdrom diff -r /cdrom files umount /cdrom No errors! It's not a coaster! |
|
Label it
|
Philip Hallstrom wrote in to tell us about labelling the CDs. I had tried
to do this and failed. Here's what you do:
|
|
Creating an ISO from a CD
21 September 2001
|
|
If you want to create an ISO from a CD, here's how I did it (my thanks to Greg Lehey for this solution as posted to the FreeBSD -questions mailing list): Data on CDs is written in blocks of 2 kB. By default dd reads 512So I tried it:
Then I verified that I could mount that ISO:
That looks good enough to me! |