The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Things look quiet here. But I've been doing a lot of blogging at dan.langille.org because I prefer WordPress now. Not all my posts there are FreeBSD related. I am in the midst of migrating The FreeBSD Diary over to WordPress (and you can read about that here). Once the migration is completed, I'll move the FreeBSD posts into the new FreeBSD Diary website.

cdrecord - writing your own CDs 14 December 2000
Need more help on this topic? Click here
This article has 5 comments
Show me similar articles

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

http://cdrecord.berlios.de/old/private/cdrecord.html

The FAQ and How-To are at:

http://cdrecord.berlios.de/old/private/man/cdr_readme.html

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):

# cdrecord -dummy -eject blank=all dev=0,5,0
Cdrecord 1.9 (i386-unknown-freebsd4.2) 
                             Copyright (C) 1995-2000 Jörg Schilling
scsidev: '0,5,0'
scsibus: 0 target: 5 lun: 0
cdrecord: No such file or directory. Cannot open SCSI driver.
cdrecord: For possible targets try 'cdrecord -scanbus'. Make sure 
                                                       you are root.

That was odd.  So I took their suggestion and tried the scanbus...

# 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 ' 'ST318436LW ' '0010' Disk
0,1,0 1) 'SEAGATE ' 'ST318436LW ' '0010' Disk
0,2,0 2) *
0,3,0 3) *
0,4,0 4) *
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) 'PLEXTOR ' 'CD-R PX-W124TS' '1.05' Removable CD-ROM
1,6,0 106) *
1,7,0 107) *

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:

da0 at ncr0 bus 0 target 0 lun 0
da0: <SEAGATE ST318436LW 0010> Fixed Direct Access SCSI-3 device 
da0: 20.000MB/s transfers (10.000MHz, offset 8, 16bit), Tagged
                                                    Queueing Enabled
da0: 17522MB (35885168 512 byte sectors: 255H 63S/T 2233C)
da1 at ncr0 bus 0 target 1 lun 0
da1: <SEAGATE ST318436LW 0010> Fixed Direct Access SCSI-3 device 
da1: 20.000MB/s transfers (10.000MHz, offset 8, 16bit), Tagged
                                                    Queueing Enabled
da1: 17522MB (35885168 512 byte sectors: 255H 63S/T 2233C)
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 speed to suit your CD drive):

# cdrecord -eject speed=4 blank=all dev=1,5,0 
Cdrecord 1.9 (i386-unknown-freebsd4.2)
                             Copyright (C) 1995-2000 Jörg Schilling
scsidev: '1,5,0'
scsibus: 1 target: 5 lun: 0
Using libscg version 'schily-0.1'
Device type    : Removable CD-ROM
Version        : 2
Response Format: 2
Capabilities   : SYNC LINKED 
Vendor_info    : 'PLEXTOR '
Identifikation : 'CD-R   PX-W124TS'
Revision       : '1.05'
Device seems to be: Generic mmc CD-RW.
Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
Driver flags   : SWABAUDIO
cdrecord: Drive needs to reload the media to return to proper status
Starting to write CD/DVD at speed 4 in write mode for single session
Last chance to quit, starting real write in 1 seconds.

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).

-J     Generate Joliet directory records  in  addition  to
       regular iso9660 file names.  This is primarily use-
       ful when the discs are to be used on Windows-NT  or
       Windows-95  machines.    The  Joliet  filenames are
       specified in Unicode and each path component can be
       up to 64 Unicode characters long.

-L     Allow ISO9660 filenames to  begin  with  a  period.
       Usually,  a  leading dot is replaced with an under-
       score in order to maintain MS-DOS compatibility.
       This violates the ISO9660 standard, but it  happens
       to work on many systems.  Use with caution.
-P publisher_id
       Specifies  a  text string that will be written into
       the volume header.  This should describe  the  pub-
       lisher of the CDROM, usually with a mailing address
       and phone number.  There is space on the  disc  for
       128  characters of information.  This parameter can
       also be set in the file .mkisofsrc with PUBL=.   If
       specified  in both places, the command line version
       is used.

-p preparer_id
       Specifies a text string that will be  written  into
       the  volume  header.  This should describe the pre-
       parer of the CDROM, usually with a mailing  address
       and  phone  number.  There is space on the disc for
       128 characters of information.  This parameter  can
       also  be set in the file .mkisofsrc with PREP=.  If
       specified in both places, the command line  version
       is used.
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 speed to suit your CD drive):

# cdrecord -eject speed=4 dev=1,5,0 cdimage.raw
Cdrecord 1.9 (i386-unknown-freebsd4.2) 
                              Copyright (C) 1995-2000 Jörg Schilling
scsidev: '1,5,0'
scsibus: 1 target: 5 lun: 0
Using libscg version 'schily-0.1'
Device type : Removable CD-ROM
Version : 2
Response Format: 2
Capabilities : SYNC LINKED 
Vendor_info : 'PLEXTOR '
Identifikation : 'CD-R PX-W124TS'
Revision : '1.05'
Device seems to be: Generic mmc CD-RW.
Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
Driver flags : SWABAUDIO
Starting to write CD/DVD at speed 4 in write mode for single session
Last chance to quit, starting real write in 1 seconds.
Track 01: Total bytes read/written: 5425152/5425152 (2649 sectors).

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 speed to suit your CD drive).

# cdrecord -eject speed=12 dev=1,5,0 racing.raw
Cdrecord 1.9 (i386-unknown-freebsd4.2)
                              Copyright (C) 1995-2000 Jörg Schilling
scsidev: '1,5,0'
scsibus: 1 target: 5 lun: 0
Using libscg version 'schily-0.1'
Device type    : Removable CD-ROM
Version        : 2
Response Format: 2
Capabilities   : SYNC LINKED 
Vendor_info    : 'PLEXTOR '
Identifikation : 'CD-R   PX-W124TS'
Revision       : '1.05'
Device seems to be: Generic mmc CD-RW.
Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
Driver flags   : SWABAUDIO
Starting to write CD/DVD at speed 12 in write mode for single 
                                                            session.
Last chance to quit, starting real write in 1 seconds.
Track 01: Total bytes read/written: 653717504/653717504 (319198 
                                                         sectors).

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:

I just read you article on cdrecord and noticed that you don't use -V flag to mkisofs. If you do something like:

mkisofs -V "MYLABEL" ....

then when you put the CD into a mac/windows box (I know I know, but it happens) it will show up as "MYLABEL" which can be nice...

-philip

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 512
bytes at a time, and the CD driver doesn't support this. It would
work if you use bs=2k. For the sake of efficiency, however, you
should select a larger block size, say 64 kB:
dd if=/dev/cd0a of=/home/disc.iso bs=64k
So I tried it:
# dd if=/dev/cd0a of=/home/disc.iso bs=64k
9428+1 records in
9428+1 records out
617930752 bytes transferred in 180.846213 secs (3416885 bytes/sec)
Then I verified that I could mount that ISO:
# vnconfig /dev/vn0c /home/disc.iso
# mount -t cd9660 /dev/vn0c /mnt
# ls /mnt
AUTORUN.INF Manual Readme.doc Sound Files
DXMedia Multimedia Tutorials STUDIO.ICO pinpctv.inf
DirectX OEM Samples welcome.exe
Driver PCTV.CAB Setup
# umount /mnt
# vnconfig -u /dev/vn0c

That looks good enough to me!


Share
Need more help on this topic? Click here
This article has 5 comments
Show me similar articles