CD-ROM and Linux
CD-ROM stands for Compact Disc Read-Only Memory, a storage medium utilizing an optical laser to read microscopic pits on the aluminized layer of a polycarbonate disc. The same format is used for audio compact discs.
The storage capacity of a CD-ROM is approximately 650MB, equivalent to over 500 high density 3.5" floppy disks or roughly 250,000 typed pages.
First-generation drives (known as single speed), provide a transfer rate of approximately 150KB (kilobytes) per second. Double-speed drives are commonly available, and triple- and quad-speed drives have recently been introduced.
Most CD-ROM drives use either the Small Computer Systems Interface (SCSI) or a vendor-proprietary interface (which is often provided on a sound card). They also typically support playing audio CDs via an external headphone jack, line-level output, or speakers. A third type of CD-ROM interface, based on an extension of the IDE hard disk interface, has also recently become available.
CD-ROMs are usually formatted with an ISO-9660 (formerly called High Sierra) file system. This format restricts filenames to the MS-DOS style (8+3 characters). The Rock Ridge Extensions use undefined fields in the ISO-9660 standard to support longer filenames and additional Unix-style information (e.g., file ownership, device files, symbolic links, etc.).
Photo-CD is a standard developed by Kodak for storing photographic images as digital data on a CD-ROM. Photographic film can be transferred to a Photo-CD and, with appropriate software, you can view the images on a computer, perform further image processing, or send them to a printer. Up to 100 photographs can be stored on a CD with an image quality that is typically much higher than can be obtained using other methods, such as scanners.
CD recorders have recently become available. They use a different media and specialized equipment for recording, but the resulting disc can be read by any CD-ROM drive. (This is the same “write once” technology used for Photo-CD.)
The primary advantages of CD-ROM over other mass- storage media are its high storage capacity, high reliability, and low cost.
The drawbacks are that it is read-only, slower-than-hard-disk media, and the discs can be damaged if mishandled.
Linux provides good support for CD-ROM. The dynamic buffer cache used for the hard disk subsystem is also used for CD-ROM access, improving performance. Depending on the type, multiple drives can be supported. (The Panasonic driver, for example, supports up to 16 drives.)
Linux fully supports the Rock Ridge Extensions to the ISO-9660 file system, making all of the features of the hard disk file systems available, including long filenames, file permissions, links, and device files. PhotoCD is also supported by some of the CD-ROM drivers.
Many vendors (I know of at least ten) are now offering CDs of Linux source code, binaries, and documentation at reasonable prices. Many of these feature easy to use menu-driven installation programs. A single CD-ROM can hold a full Linux distribution, as well as all of the files from the two major Internet archive sites, with room to spare. By comparison, a recent Linux distribution can fill as many as 50-3.5 inch floppies.
Finally, most CD-ROM drives support playing audio CDs, so you can listen to music while waiting for the latest Linux kernel to compile.
Linux supports virtually all SCSI CD-ROM drives, provided that a supported SCSI host adaptor is used.
Many of the popular proprietary drives are supported, including models produced by Sony, Mitsumi, and Panasonic/Matsushita.
CD-ROMs based on the enhanced IDE standard are not yet officially supported by Linux, although at the time of this writing, at least one driver is in alpha testing.
By the time you read this, more devices will likely be supported, either as part of the standard Linux kernel or as patches. See the CD-ROM HOWTO document for a detailed list of the latest supported hardware.
Setting up Linux to use a CD-ROM involves four steps:
Installing the hardware
Configuring the Linux kernel
Creating the necessary device files
Mounting the media
I will cover them briefly here; see the Linux CD-ROM HOWTO for more details.
The first step, installation, is dependent on the type of drive. Follow the instructions provided by the manufacturer or have the installation performed by your dealer. There are no special installation requirements for Linux.
Next, the Linux kernel must be configured. In some cases, you may be able to use a pre-compiled kernel that has the necessary drivers, but I recommend compiling it yourself; it will do you good! For SCSI drives you need to configure in SCSI CD-ROM support and the driver for the SCSI host adaptor being used.
For the proprietary CD-ROM interfaces, select the appropriate driver (e.g., Sony CDU31A).
In order to mount CD-ROMs, you must also configure in support for the ISO-9660 file system. If you have a sound card, now would be a good time to configure the kernel sound driver as well.
The third step is to create the appropriate device files. If you are running a standard Linux distribution you may have already done this during system installation. It's a good idea to verify these; the CD-ROM HOWTO lists the device file types, which are drive dependent.
You should now be ready to compile and boot the newly configured kernel. Verify that the CD-ROM was detected by looking at the kernel boot messages; here is the output on my system:
SBPCD version 2.5 Eberhard Moenkeberg <emoenke@gwdg.de> SBPCD: Looking for a SoundBlaster/Matsushita CD-ROM drive SBPCD: Trying to detect a SoundBlaster CD-ROM drive at 0x230. SBPCD: - Drive 0: CR-562-x (0.76) SBPCD: 1 SoundBlaster CD-ROM drive(s) at 0x0230. SBPCD: init done.
To mount a CD-ROM, insert it in the drive and use the mount command (as root). A typical command line is the following:
% mount -t iso9660 -r /dev/cdrom /mnt
The example above assumes that the CD-ROM device file is /dev/cdrom and the disc is ISO-9660 formatted (this is almost always the case). The -r option indicates that the disc is to be mounted read-only. If successful, the CD can now be accessed under the directory /mnt.
For a more permanent setup, you may wish to mount the CD under a more meaningful name such as /cdrom. By adding an entry to the /etc/fstab file you can have a CD-ROM automatically mounted when Linux boots; see the fstab(5) man page for details.
When finished with the CD, it can be unmounted using the umount command (again, run this as root):
% umount /mnt
If you want to allow non-root users to mount and unmount CD-ROMs, you can use the “user” option provided by some mount commands. If you make an entry such as the following in /etc/fstab:
/dev/sbpcd /cdrom iso9660 user,noauto,ro
then an ordinary user will be permitted to mount and unmount the drive using these commands:
% mount /cdrom % umount /cdrom
The disc will be mounted with some options that help ensure security (e.g., programs on the CD cannot be executed and device files are ignored). Another method is to obtain or write a program such as usermount which runs setuid to root and allows restricted mounting of specific devices (e.g., CD-ROM and floppies) for non-root users.
PhotoCDs use an ISO-9660 file system to store image files in a proprietary format, at several different resolutions. Not all CD-ROM drives support reading PhotoCDs. If yours does, you can mount it and use a program such as hpcdtoppm to convert the files to a format that can be displayed using graphics file viewers such as xloadimage or xv.
The hpcdtoppm program is part of the PBM (portable bit map) utilities, available on many Internet archive sites (look for pbm or netpbm).
The program xpcd is an X11-based utility for manipulating PhotoCD images. You can select the images with a mouse, preview them in a small window, and load the image with any of the five possible resolutions. You can also mark a part of the image and load only the selected part. This program can be found at ftp.cs.tu-berlin.de in the file /pub/linux/Local/misc/ xpcd-0.2.tar.gz.
Several programs are available that allow playing audio CDs, either through a headphone jack or an attached sound card. workman, supplied with many Linux distributions, is one such program. It sports a graphical user interface that resembles the controls provided on audio CD players. Simple command-line CD player programs also exist. Note that to play an audio CD you should not try to mount it.
The CD player programs simply route the analog output of the drive to an external device. Some CD-ROM drives also support reading the digital sound data contained on audio CDs. Using a program such as cdda2wav you can save audio tracks from a CD-ROM as a sound file (e.g., in .wav format).
The Inheriting File System (IFS) is a kernel driver that allows mounting multiple file systems at the same point. By mounting a hard disk directory over a CD-ROM file system, you can effectively obtain a writable CD-ROM file system.
At the time of this writing, an experimental version of IFS, written by Werner Almesberger for the 0.99 Linux kernel, is available as a kernel patch.
If you want to create your own CD-ROM, either by using a writable CD drive or sending a tape to a vendor to be mastered, there are some tools available under Linux that you can use.
The mkisofs package allows creating an ISO-9660 file system on a disk partition. This can be used to assist in creating and testing CD-ROM file systems before mastering discs.
There are also some utilities available for verifying the format of ISO-9660 file systems; these can be useful for checking suspect CD-ROMs.
If you encounter problems setting up CD-ROM support under Linux, here is a list of things to check for. (See the CD-ROM HOWTO for more information.)
Are the appropriate CD-ROM driver(s) compiled in the kernel? Try the command cat/proc/devices to see which drivers are installed.
Are you running the newly configured kernel? Use uname -a and check the time-stamp to see.
Is the drive recognized at boot time? The dmesg command should redisplay the boot messages if they scroll by too quickly to read.
Did you create the proper device files and set protections? The /dev/MAKEDEV script is one way to do this.
Is the ISO-9660 file system compiled in the kernel? Try cat /proc/filesystems and look for iso9660.
Is there a known good CD-ROM (not audio CD) in the drive?
Did you use the correct options to mount? You need to specify -t iso9660, -r (read-only), the CD-ROM device file, and an empty directory. You should run this as user “root”.
Can you read data from the drive? Try using the dd command and checking for disk activity (e.g., dd if=/dev/cdrom of=/dev/null bs=2048).
For some drives, if they are located at a non-standard I/O address, you may need to edit the appropriate kernel driver header file.
Here are a number of additional useful sources of information related to CD-ROM under Linux.
The Linux CD-ROM, SCSI, and Distribution HOWTO documents are freely available from major Linux archive sites, including sunsite.unc.edu in the directory /pub/Linux/docs/HOWTO. For those without network access, printed copies of the Linux HOWTOs are also published by a number of vendors, or you may be able to find them on a local computer bulletin board system.
The latest and most complete information on the Panasonic/SoundBlaster CD-ROM kernel driver can be found in the file README.sbpcd, usually found in the directory /usr/src/linux/drivers/block.
Additional information on commands such as mount and umount can be found in the corresponding Linux man pages.
For those with access to Usenet, the following news groups discuss information related to CD-ROM:
comp.publish.cdrom.hardware
comp.publish.cdrom.multimedia
comp.publish.cdrom.software
comp.sys.ibm.pc.hardware.cd-rom
alt.cd-rom
alt.cd-rom.reviews
A Frequently Asked Questions (FAQ) document for the alt.cd-rom newsgroup is also available; it is archived on many Internet sites including rtfm.mit.edu.
The Internet site ftp.cdrom.com has a large archive of CD-ROM information and software; look in the directory /pub/cdrom.
The Linux Documentation Project has produced several books on Linux; the most useful for new users is Linux Installation and Getting Started. These are freely available by anonymous FTP from major Linux archive sites or can be purchased in hard-copy format.
The Linux Software Map (LSM) is an invaluable reference for locating Linux software, including the programs mentioned in this article. The LSM can be found on various anonymous FTP sites, including sunsite.unc.edu:/pub/Linux/docs/LSM.gz.
(Jeff.Tranter@Software.Mitel.com) is a software designer for a telecommunications company in Ottawa, Canada. He has been using Linux for almost two years and is the author of the Linux Sound and CD-ROM HOWTO documents.