Saturday, February 21, 2009

Mounting CD/DVD-ROM

Because a DVD-ROM drive is a "removable" storage device, you may find that you can't access a DVD after inserting it. You have to manually enter a command to "mount" the DVD-ROM drive before you can access it. On my system, the DVD-ROM drive is the first drive (master) on the secondary IDE channel. As a result, the command I use to mount my DVD-ROM drive is:

mount -t iso9660 /dev/hdc /cdrom

I know this looks a little cryptic at first but it's really quite simple.

  • mount makes a device part of the file system.
  • -t iso9660 specifies the format of the file system being mounted. (The iso9660 is the standard format for data CDs (and most DVDs) but would be msdos if we were mounting a floppy drive with a DOS-formatted floppy in it.)
  • /dev/hdc is the path to the DVD-ROM drive's device driver file. The c in the hdc indicates the first hard-drive on the secondary IDE channel. With SCSI hard-drives the third hard-drive would be sdc.)
  • /cdrom is the directory to "map" the device to in the file system so it can be accessed. This has to be an existing directory but it can actually be any directory you want. You could use the mkdir command to create a directory called "shiny-spinning-thing" off the root of the file system and replace /cdrom with /shiny-spinning-thing in the above command if you wanted to.

Using the above mount command simply maps the DVD-ROM drive to the /cdrom directory (which was created during the installation). The directory a device gets mapped to is called the "mount point". As such, in order to access the files on the DVD-ROM once it's been mounted you just go to the mount point its been mapped to by entering

cd /cdrom

and use the ls command to view a list of the files on it. If you get an error along the lines of:

kernel does not recognize /dev/hdc

it's likely your DVD-ROM drive is connected as the slave on the primary IDE channel (i.e. it's /dev/hdb).

Tip: The mount command to access a DOS formatted floppy in the first floppy drive would be:

mount -t msdos /dev/fd0 /floppy

Note that Debian creates the /cdrom and /floppy directories off of the root of the file system during the installation. Other Linux distros and UNIX more often put them under the /mnt directory. In order to mount a DVD drive on these systems you simply change the target directory in the command:

mount -t iso9660 /dev/hdc /mnt/cdrom

Just as you mounted the removable disk to access it, you have to unmount it when you are done. Pressing the eject button on the DVD drive won't open the tray until you do unmount the drive. For this you just use the umount and specify its mount point in the file system:

umount /mnt/cdrom

 
Things You Should Know About Linux !!!