Whole document tree
    

Whole document tree

Mounting and unmounting drives

Mounting and unmounting drives

As we mentioned earlier, the directories on a UNIX system are organized in a tree, with the top level directory being /. Unlike some other operating systems such as MS-DOS, there are no special names for files on your floppy disk or CD-ROM: all the files accessible to your system must appear in the main directory tree starting with /.

Thus, before you can access files on a floppy diskette or a CD-ROM, you must give to your system a command to incorporate the contents of this diskette into the main directory tree, which is referred to as mounting the diskette. You can think of it as the software analog of connecting the drive to your system. Typically the contents of the CD-ROM will appear under the name /mnt/cdrom; the floppy diskette under /mnt/floppy (these are called the mount points and are defined in the special configuration file, /etc/fstab). Accessing a drive in this fashion doesn't mean that the system will copy all the files from the CD to the directory /mnt/cdrom. Instead, it means that the directory /mnt/cdrom represents the CD-ROM: When a program tries to access, say, a file called /mnt/cdrom/index.html, the system will look for file index.html on the CD-ROM.

So, in short: before you can use files on a drive, you must "mount" it. Similarly, before removing the disk from the drive, you must unmount it.

When using GNOME, you usually do not have to worry about mounting and unmounting: GNOME scans the appropriate configuration file and places the icons for all drives on your desktop. Double-clicking on any of these icons automatically mounts the corresponding drive (if it was not already mounted) and starts the file manager in the appropriate directory. Similarly, if you right-click on the drive icon and choose the command Eject device from the pop-up menu, GNOME automatically unmounts it before ejecting. You can also mount/unmount a drive by right-clicking on its icon on the desktop and choosing Mount device or Unmount device from the pop-up menu, or by using the disk mount applet.

Note that you can't unmount a drive if it is being used by some program; for example, if you have a terminal windows open in a directory on the drive you're trying to unmount. So, if you get the error message "Device busy" while trying to unmount a drive, make sure that none of your open applications is accessing a file or directory on this drive.

However, GNOME cannot prevent you from ejecting the disk using the physical eject button on the drive itself — in this case, it is your responsibility to unmount the drive before doing so. For CD and Zip drives, the system blocks the eject button on the drive while the drive is mounted; for floppy drives this is technically impossible.

ImportantIMPORTANT
 

If you eject a floppy disk using the eject button on the drive without first unmounting it, you may lose your data!

Some systems are running special programs such as supermount or magicdev which automatically mount a drive when a disk is inserted and unmount a drive if it hasn't been used for a specified period of time. In this case, you will probably never need to worry about mounting/unmounting drives yourself; you don't even need to read this section.

Allowing users to mount and unmount drives carries some security risks, so many multi-user systems are configured so that only root can mount or unmount drives. This is the most probable cause of error messages you may be getting while trying to mount a drive. In this case, discuss this matter with your system administrator.

If the computer is your personal workstation or home computer and you are not worried about security, you can give mount permission to ordinary users. The easiest way to allow this is to use the application linuxconf (which can only be run by root). Just select the drive you want to access in the Access local drive section. In the Options tab select the User Mountable option. Your drive will now be mountable by users.

If linuxconf is not available, then you must manually edit the file /etc/fstab to include user access. This is done by adding the "user" attribute to the drive. For example:

If your fstab file contains a line like this:

/dev/cdrom /mnt/cdrom iso9660 exec,dev,ro,noauto 0 0
      

add the word "user" to the fourth column:

/dev/cdrom /mnt/cdrom iso9660 user,exec,dev,ro,noauto 0 0