Home Map Index Search News Archives Links About LF
[Top bar]
[Bottom bar]
[Photo of the Author]
by Yao Feng

About the author:

He is a Linux fan besides working in a campus network center. Hobbies:hamradio, swimming. Using Linux as a normal user for one year, doing system administration on Linux/Unix for another year. Finishing the graduate thesis on billing systems with a Linux based proxy server.

Content:

How to use your CD-ROM under Linux

[Illustration]

Abstract:

This article gives a short but useful description on how to use your CD-ROM under Linux. It describes how to find the CD-ROM device, mount (make available) the CD-ROM, read the contents, umount it and gives some hints for troubleshooting.



   

Find out what the name of your CD-ROM device is

You got you Linux-box to work, now you want to copy a file from a CD-ROM to your hard disk.
Check if the CD-ROM device was identified correctly by the Linux kernel using the command dmesg.
If you have an ATAPI cdrom connected via IDE then this might look like:
$ dmesg |more
.
.
.
hda: QUANTUM FIREBALL CR8.4A, ATA DISK drive
hdc: CD-ROM CDU701, ATAPI CDROM drive
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
ide1 at 0x170-0x177,0x376 on irq 15
hda: QUANTUM FIREBALL CR8.4A, 8063MB w/418kB Cache, CHS=16383/16/63, (U)DMA
hdc: ATAPI 14X CD-ROM drive, 128kB Cache
Uniform CDROM driver Revision: 2.55
.
.
.


If you have an SCSI cdrom then it might look like:
$ dmesg |more
.
.
.
Detected SCSI removable disk sdc at scsi0, channel 0, id 5, lun 0
Vendor: PLEXTOR Model: CD-ROM PX-12TS Rev: 1.03
Type: CD-ROM ANSI SCSI revision: 02
Detected scsi CD-ROM sr0 at scsi0, channel 0, id 6, lun 0
scsi : detected 1 SCSI cdrom 3 SCSI disks total.
.
.

The 'hdc: CD-ROM CDU701, ATAPI CDROM drive' line tells us that you have a CD-ROM IDE/ATAPI-CD drive attached on the computer. Linux assign it a device name-'hdc' for access later on. The name of device depends on the hardware type and it is hdc in the first case and sdc in the case where you have SCSI CD-ROM.  

Mount (make available) your CD-ROM

Generally you must be the super user (root) to do that, but in chapter mounting a CD-ROM as normal user we will see how this can be done by anybody (It is generally best to do as little as possible as user root). Mounting is necessary before you can read the contents on a CD-ROM disk. Insert a CD-ROM disk in your CD-ROM, make sure the directory /cdrom exists and type command :
#mount /dev/hdc -t iso9660 -r /cdrom
in case of a scsi cd-rom this is
#mount /dev/sdc0 -t iso9660 -r /cdrom

The device name of the CD-ROM is the one that was shown in the output of the dmesg command.
 

Accessing your CD-ROM

After the cdrom is mounted you can check with the disk free command (df) that it is correctly mounted at the /cdrom directory:
$ df
Filesystem         1024-blocks 
Used Available Capacity Mounted on
/dev/sda1    2974519   1516768    1303931   54%   / 
/dev/sda3    2686158   2378788    153548    94%   /home
 /dev/hdc     603646     603646       0     100%  /cdrom

Now you can now access your cd-rom like a normal directory at /cdrom.  

Unmounting your CD-ROM

After finishing your work, you may want to take the CD-ROM out, but you find that the push button at the CD-ROM drive front panel does no longer open the drive.
The CD-ROM is *locked*. You should first unmount (the command is umount with out the n) the cdrom. Try following command as super user (root):
#umount /cdrom
or alternatively you can type
#umount /dev/hdc
In case of the scsi cd this is:
#umount /dev/sdc0

After that you can take it out by pushing the button on the drive front panel. You can also use a program called eject to open the cdrom drive via command.    

Mounting and unmounting without being root

When you are logged in as root you can do anything but you can also accidently do more than you wanted to. It is therefore better to make the cdrom mountable for ordinary users. To give the privileges to mount a drive to any user you must first log in as root and do 3 things:

  1. make the directory /cdrom world writable
  2. make the device world writable
  3. edit the fstab

To make the directory /cdrom world writable you type (while no cdrom is mounted!):
#chmod 777 /cdrom

To make the device world writable you type (use the device name as described in the first chapter):
for the ATAPI cdrom:
#chmod 666 /dev/hdc
for the SCSI cdrom:
#chmod 666 /dev/scd0

Now you must edit /etc/fstab and give the permission to mount the cdrom to any user. This is done by inserting the line following line:
/dev/hdc  /cdrom     iso9660 ro,noauto,user 0 0
In the case of the scsi cdrom this looks like:
/dev/sdc0  /cdrom     iso9660 ro,noauto,user 0 0
Please note that there might already be a line for the /dev/hdc device (or /dev/sdc0) in this case you have to edit the line and not add a new entry. The line tells Linux on which directory to mount the cdrom and with device to use. It tells Linux also that the file system is iso9660, that it should be mounted read only and that it should never be mounted at startup (when there might not be a CD in the drive). The option "user" means that any user can mount the drive.

Save the fstab file and log in as normal user. Now insert a CD into the drive and mount it with the command:
$mount    /cdrom
Easy, isn't it?
It is now possible to use this short form because Linux can get all the other parameters from /etc/fstab.

 

Troubleshooting

Be sure you are *not* in any directory below the /cdrom directory tree; check if someone else is in one of the directory of /cdrom. If you can't find out who is using it then it is probably some background process of yours that is using the drive. To find out which one, you can type /usr/sbin/fuser /cdrom Terminate the process and you can umount + eject the CD. You check the kernel message before you want to mount the CD-ROM for getting the correct device name and its annoying you that you forget it all the time. Here is a solution: Create a soft link for your CD-ROM device:
#ln -s /dev/hdc /dev/cdrom
Now you can mount /dev/cdrom to /cdrom and forget if it is /dev/hdc or /dev/hdb. (But look also at chapter "Mounting/unmounting without being root" which shows an even better way to do this) Look at chapter "Mounting/unmounting without being root" It is not necessary to mount a audio-cd. Try programs such as workbone (for console) or workman and xplaycd (for X-win) if your CD-ROM hardware has no play music buttons.
Webpages maintained by the LinuxFocus Editor team
© Yao Feng
LinuxFocus 1999

1999-09-13, generated by lfparser version 0.7

mirror server hosted at Truenetwork, Russian Federation.