How to Write a CD.

(Using free software on a Unix workstation).

This is intended for system administrators who want to back up files to a writeable CD.   Jörg Schilling's CDrecord software is used. These notes refer mainly to Solaris on Sun computers, however there is a list of supported operating systems at the CDrecord release information site.


Australian National University NMR Centre home page

CD-Recordable FAQ   |   Sun CD-ROM FAQ



To write a CD you need to:

  1. connect a SCSI CD writer to your computer. If your operating system is SunOS / Solaris, you will need to install scg - the SCSI General Driver. This is used by the kernel to control the CD writer.
  2. use the mkisofs program to create a disk image of the data to be backed up,
  3. use the cdrecord program to write the disk image to a CD.
  4. optionally use the sformat program to verify the data on the CD.

Notes:

Software Versions:
These notes were originally written with reference to CDrecord-1.6.1 and mkisofs-1.11. I have since updated them for CDrecord-1.9, however the method of installation does not appear to have changed significantly between versions 1.6.1 and 1.9.
The current version has changed its name to cdrtools 2.0, but I haven't had a look at that yet.
CDrecord-1.9 includes mkisofs-1.13.   Eric Youngdale wrote the first versions (1993 ... 1998) of mkisofs but recent development has been by Jörg Schilling. Also note that Solaris 8 comes with mkisofs version 1.11, so if you install version 1.13 on Solaris 8 you'll need to be carefull to specify the path to the newer version to ensure that you are actually using version 1.13. (Or just delete the version that comes preinstalled with Solaris 8).

The software for both creating the disk image and driving a CD writer connected to a Unix host is available at ftp.berlios.de/pub/cdrecord/. If you're running SunOS or Solaris you will also need the scg driver (see the scg section below).

Cdrecord used to be available as either source or binary, but last time I looked there were no binary distributions at the ftp.fokus.gmd.de site. However a binary distribution of cdrecord.1.8.24 which includes mkisofs 1.12b5 is available at the Solaris Package Archive. This site (and its mirrors) contains packages that can be easily installed with the Solaris pkgadd command. See the README file for further details.

I have compiled a binary of mkisofs suitable for Suns running Solaris 2. Right-click on the link and select Save Link As. Then chmod 755 mkisofs and copy it to a suitable directory.

The rest of this section is only applicable if you downloaded the software from the ftp.fokus.gmd.de site.

The file cdrecord-1.9.tar.gz contains the source code for both cdrecord and mkisofs. The source code for various versions of mkisofs is also available separately in the mkisofs directory of the ftp site. The latest version as of January 2001 is mkisofs-1.13.tar.gz.

Even if you plan to get the binaries from the Solaris Package Archive it is a good idea to download source so that you can peruse all the README files. In either case, you will need gzip to uncompress the files.

If you want to compile the programs from source, you will need a C compiler such as gcc and a make program. The 'make' that comes with Solaris 7 (/usr/ccs/bin/make) will do, GNU make is better, but Jörg Schilling's first preference is his smake.

Untar the source and change to the cdrecord-1.9/DEFAULTS directory. If you're using gcc, edit Defaults.sunos5, commenting the

DEFCCOM=       cc
line and uncommenting the
DEFCCOM=        gcc
line. Also, if you want the executables installed somewhere other than /opt/schily, change the INS_BASE line to read (for example)
INS_BASE=	/usr/local
Change back to the cdrecord-1.9 directory and type make to start the compilation. If all goes well, you can then type (as root) make install.
    The INSTALL file in the cdrecord-1.9 directory mentions some special preparation if you're using GNU make. (See the Hints for compilation: section). I had no problems with GNU Make version 3.77 under Solaris. The README.gmake file hints that any problems with GNU Make are platform specific, so I suggest you forget about the special preparation unless you encounter problems.

make install copies the following files into locations under the "INS_BASE" directory...
binlibinclude 
cdrecord
mkisofs
mkhybrid
devdump
isodump
isoinfo
isovfy
cdda2wav
readcd
libschily.a
libdeflt.a
libscg.a
libhfs.a
libfile.a
libunls.a
align.h
avoffset.h
various man files

Note that if you set INS_BASE to /usr/local as described above, it is not necessary to edit the LDPATH line in the Defaults.sunos5 file. The library files are correctly installed in /usr/local/lib.
Version 1.6.1 of CDrecord only produced   cdrecord,   mkisofs   and   libschily.a   when you typed make. The other binary, library and header files listed above are new additions. Mkhybrid is just a hard link to mkisofs.

 

Installing scg

You only need to do this if you are running SunOS or Solaris. It is in the form of a binary package that you install before using CDwrite for the first time. It is not included with the cdrecord tar file and must be downloaded separately from the ftp site.
The installation method for SunOS 4.1.3 is not covered here - see the appropriate README at the ftp site.

The ftp site contains 2 Solaris packages...
  SCHILYscg.i386.tar.Z   (for Intel based computers) and
  SCHILYscg.sparc.tar.Z   (for Suns).
There are also numerous updates to the actual scg driver, all having filenames starting with scg. At the time of writing (October 1999, updated Feb 2001) the recommended file for Suns running a 32bit kernel is scg-sparc-sol2.4.beta. This includes all versions of Solaris prior to Solaris 7, as well as Solaris 7 and 8 running a 32bit kernel. I am presently running with scg-sparc-sol2.4.beta on Solaris 8 with a 32bit kernel.
If you are running a 64bit kernel with Solaris 7 or 8, see the note below. (You can see what kernel you are running using the isainfo -b command. It simply prints 32 or 64 for 32bit or 64bit kernels respectively).
You can ftp to ftp.fokus.gmd.de/pub/unix/kernel/scg/ and get SCHILYscg.sparc.tar.Z and scg-sparc-sol2.4.beta (make sure to use binary mode) or you can visit this site with your browser, then select the required file with your right mouse button and select "Save Link As".
A couple of important notes from the README file in the ftp site:

As described in the README file, the installation procedure for Suns is to (as root) first copy the update file to the right place, then install the package:

  cp scg-sparc-sol2.4.beta /kernel/drv/scg
  uncompress SCHILYscg.sparc.tar.Z
  tar -xvf SCHILYscg.sparc.tar
  pkgadd -d .
When asked if pkgadd should overwrite the conflicting files (i.e. the file you placed in /kernel/drv) answer with 'no'.
The screen output produced during installation may make this clearer.

 

After you have successfully installed CDrecord and scg, connected your CD writer and turned it on, you might like to try the command (as root)

cdrecord -scanbus
This should print a line for every SCSI device on your system, including your CD writer.


Creating the Disk Image

The program mkisofs is used to create an image of the files to be recorded on the CD. A CD can hold 650 Mbytes of data, so if you are writing enough data to fill up a CD, you will need 650 - 670 Mbytes available on a hard disk to hold the disk image. Also of course, if you have more than 650 Mbytes of data, you have to choose which data to back up and which to leave out, so that the disk image you create will "fit" onto the CD.

So far, I have always written the whole CD in one go. See the file README.multi in the cdrecord source if you want to write multi-session CDs. Another source of information is the Multi-session CD Mini Howto.

Although the type of data is irrelevant, this section shows how I use mkisofs to make a disk image of Varian Nuclear Magnetic Resonance data. On our system the NMR data is kept in a separate partition called "fids". Users have their own data directories, so the directory structure looks like this:


   /fids -+- angusfids/  dept.fid   cosy.fid   etc.
          |
          +- harryfids/  . . .
          |
          +- jonesfids/  . . .
          |

and so on. To decide which data will fit onto a CD, open an Xterm, change to the /fids directory and type
  du -sk *
The output looks like this:
 
74284   angusfids
64735   harryfids
39349   jonesfids
2       lornafids
192562  maryfids
  (and so on)
Simply use the numbers on the left (the disk space in kbytes used by each directory) to decide which directories when backed up will consume about 650 Mbytes of disk space. If your requirements are more complex, perhaps because the data to be backed up is mixed up with other things, you may need to copy the required data somewhere before making the ISO file system. (Of course you need to have read permission on all the files to be backed up, which is why I normally do this as root).

CDs use the ISO-9660 file system. This uses the restrictive DOS-like naming convention of "up to 8 characters, followed by a period, followed by a 3 character extension". It also adds a semicolon and a file version number to the filename. So for example the name
a_long_name.fid
  would become
A_LONXXX.FID;1
This is not very satisfactory if backing up files from a Unix system, but mkisofs allows you to create an ISO-9660 filesystem with Rock Ridge extensions, which allows long, mixed-case filenames. Version 1.13 of mkisofs has many new command-line options for such things as creating hybrid ISO9660/JOLIET/HFS filesystems. The good news is that the man page now contains some usage examples, so my advice is to type man mkisofs and skip down to the EXAMPLES section (near the end) and read this first.

The command line I use to create the ISO file system is:

  cd /fids
  mkisofs -r -x./lornafids -x./zeusfids -o /some/disk/backup.img ./

The -r option creates the Rock Ridge extensions. It also sets each file on the CD to be owned by root and world readable. If you want to use Rock Ridge extensions without changing the mode or ownership of files on the CD, use the -R option instead.
The -x options are directories to exclude, either because they are empty or contain too much data to fit on the CD.
The ./   tells it to back up the current directory.

It is also possible to "graft" other directory paths onto the top level directory on the CD. In older versions of mkisofs this is done like this...

  cd /fids
  mkisofs -r -x./lindafids -o /some/disk/backup.img ./ /space/home/John/=/John
In newer versions you need to use the -graft-points option:
  mkisofs -graft-points -r -x./lindafids -o /some/disk/backup.img ./ /space/home/John/=/John
Note that it won't work without the "/" preceding the equals sign.

If none of the disks connected to the computer have enough free space to contain the disk image, pipe the image to another computer ...

  cd /fids 
  mkisofs -r -x./lindafids ./ | rsh other_host "(cd /some/disk; dd of=backup.img)"
The above example uses rsh (remote shell) to transfer the disk image. It is also possible to use ssh (secure shell) if it is installed on both the source and target computer...
mkisofs -r -x./lindafids ./ | ssh fred@other_host "dd of=backup.img"
Password:
Here the disk image will be created in fred's home directory after he types his password on "other_host".

As stated in the cdrecord man page, if your computer is fast enough and the file system is not too complicated, you can pipe the output of mkisofs directly into cdrecord without saving an image on disk. I have not tried this because I like to check the size of the image to be sure it is not too big to fit on the CD, but I guess the command would be something like

  mkisofs -r -x./lindafids ./ | cdrecord -v fs=6m speed=2 dev=5,0 -

Writing the Disk Image to a CD

We have used 2 methods of writing the disk image to a CD.
  1. Transfer the disk image to a Macintosh, and use an application such as Toast to write the CD.
    We use Fetch to transfer the disk image. Make sure to use Binary transfer mode, not Automatic or Text since anything but Binary mode corrupts the disk image.
  2. Use a CD writer connected to the Sun to write the disk image.
    The following deals only with this second method.
Turn on your CD writer and insert a blank CD. Wait a few minutes to see if the CD is spontaneously ejected. If it is, (and your computer is running the Solaris operating system) turn off volume management by typing
  /etc/rc2.d/S92volmgt stop
and reinsert it. When you have completely finished writing your CD, turn volume management back on by typing
  /etc/rc2.d/S92volmgt start
(Depending on your version of Solaris, the volume management script may have a slightly different name and be in a different directory, e.g. /etc/rc3.d/S81volmgt. But note that with recent versions of Solaris, you probably will not need to turn volume management off).
A more permanent solution is to edit /etc/vold.conf, putting a hash at the start of the "cdrom" lines, then restart volume management using the "stop" and "start" commands above. See "README.volmgt" in the cdrecord-1.9 directory. (Since upgrading to Solaris 8 I have not needed to turn off volume management, but I don't know if this is the case for all systems).

Change to the directory containing the disk image.
I become root to issue the cdrecord commands, and depending on your setup, you might need to type the complete pathname to the cdrecord executable. Sometime I'll investigate writing CDs as a non-root user.

It is a good idea to check that your computer can supply data quickly enough to write the CD at the required speed. You do this using the -dummy argument. For example:
  cdrecord -dummy -v speed=8 dev=5,0 backup.img
...where backup.img is the name of your disk image, and dev=5,0 tells it that the CD writer occupies SCSI address 5. Change this to reflect the SCSI address of your CD writer, eg. dev=6,0
The "dummy" command above goes through the process of writing the CD, but keeps the laser turned off. If all goes well, you are ready to write the CD. Note that some drives need to eject the medium before writing a new CD. Doing a -dummy test and immediately writing a real CD would not work on these devices. Press the eject button and then reinsert the CD. If the CD is not ejected, try
  cdrecord dev=5,0 -eject

To write the CD, type something like this:
  cdrecord -v speed=8 dev=5,0 backup.img
See the man page for more usage details.

The output should be similar to this...

Cdrecord 1.9 (sparc-sun-solaris2.7) Copyright (C) 1995-2000 Jörg Schilling
TOC Type: 1 = CD-ROM
scsidev: '5,0'
scsibus: 0 target: 5 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
Drive buf size : 2090928 = 2041 KB
FIFO size      : 4194304 = 4096 KB
Track 01: data  650 MB        
Total size:     746 MB (73:57.66) = 332825 sectors
Lout start:     746 MB (73:59/50) = 332825 sectors
Current Secsize: 2048
ATIP info from disk:
  Indicated writing power: 5
  Is not unrestricted
  Is not erasable
  Disk sub type: Medium Type A, low Beta category (A-) (2)
  ATIP start of lead in:  -11839 (97:24/11)
  ATIP start of lead out: 336075 (74:43/00)
Disk type:    Long strategy type (Cyanine, AZO or similar)
Manuf. index: 24
Manufacturer: SONY Corporation
Blocks total: 336075 Blocks current: 336075 Blocks remaining: 3250
Starting to write CD/DVD at speed 8 in write mode for single session.
Last chance to quit, starting real write in 1 seconds.
Waiting for reader process to fill input buffer ... input buffer ready.
Performing OPC...
Starting new track at sector: 0
Track 01:   Track 01:   1 of 650 MB written (fifo 100%).
Track 01: Total bytes read/written: 681621504/681621504 (332823 sectors).
Writing  time:  571.346s
Fixating...
Fixating time:   39.090s
cdrecord: fifo had 10737 puts and 10737 gets.
cdrecord: fifo was 0 times empty and 10521 times full, min fill was 93%.

Short Note for Users of DVD Writers

Create the disk image as above (except you can now create an image of up to 4,700,000,000 bytes). Then use
growisofs -Z /dev/dvd=backup.img
I've only done this on a Linux computer (Debian 3.1/unpatched 2.4.26 kernel) with DVD-R or DVD+R disks. It seems a version for Solaris is also available. See further notes at http://fy.chalmers.se/~appro/linux/DVD+RW/ and http://crashrecovery.org/oss-dvd/HOWTO-ossdvd.html


Verifying the CD

See the file README.verify that comes with the cdrecord source.
Whether you choose to verify the CD or not, it is a good idea to read back several files from the CD and check that they are the same as the original by doing a diff orig_file cd_file. People who backed up Varian FID data should be able to mount the CD and read datasets directly into Varian's NMR processing program to verify that the data is OK.

The sformat program can be used to check that the data was correctly written to the CD. If the CD writer is connected to target 5 on SCSI bus 0, the command to verify the CD would be: sformat -verify 5 0

NOTE: The README.verify file states that Not all CD-ROM drives support verifying.
This is certainly the case with our CD writer, and attempting to verify the CD with sformat just produces a stream of errors...

sformat: I/O error. verify: scsi sendcmd: no error
CDB:  2F 00 00 00 00 03 00 03 E5 00
status: 0x2 (CHECK CONDITION)
... and other messages not listed here.

A quick check of the filesystem is to mount the CD and to use star, (Jörg Schilling's version of the standard Unix tar command) to read all files on the CD. Note that this will not report errors due to truncated or zero-length files.
The same check can be performed using GNU tar or the standard tar that comes with Solaris:

cd /cdrom
tar cvf /dev/null .
(Don't forget the space and period after /dev/null).


Australian National University NMR Centre home page   |   Setting up netatalk on a Sun
Last modified:   1 October 2004   Chris Blake.