Without the mount and umount commands administering or using Linux would be a difficult task. These commands are in charge of making drives, CDs, floppies, etc available and unavailable for use. In this entry to the Linux Command Line series we will introduce you to mount/umount.
The mount and umount commands have a deep history in the UNIX operating system. The mounting and unmounting of removable media is one of the issues that has given many new users headaches with Linux. But what is it all about? Back in the early days of UNIX all removeable and non-removable media (such as external hard drives) had to be mounted by users. This was implemented because UNIX, being a true multi-user system, had to have a layer of security to keep one person from writing to a disk that had been removed to keep from saving a file to a removeable media that was no longer available. To this end UNIX didn't implement an "on the fly" writing to removeable media. Instead writing to removeable media is done upon issuing the umount command which writes data to the media and then safely unmounts the drive.
Today Linux is still a multi-user system so the necessity to mount and umount drives still remains. Of course most newer distributions have systems in place that automount drives for users to take advantage of.
How it works
The mount and umount commands work in conjunction with the /etc/fstab file to associate a device to a directory. Typically a device (let's use the cdrom device) will be found at /dev/cdrom and will be mounted to /media/cdrom. Now since the cdrom device is a device that any user can mount all you would have to do is put a CD into the drive and issue the command mount /media/cdrom to mount the drive and then umount /media/cdrom to unmount it. With a CD you will notice that you can not remove the media if you have not umounted the drive. This is a good thing because it keeps you from removing the media before data has been written.
Mapping with fstab
The /etc/fstab file is what is responsible for mapping devices to directories. There may be devices that you will need to add to this file. For instance, an mp3 player will not automatically have an entry to the fstab file. Without this entry only the root user can mount and unmount the device. To make the mp3 player mountable by a standard user you would need an entry in fstab like this:
/dev/sdb1 /media/mp3player auto ro,noauto,user 0 0
The above entry maps the device which is located at /dev/sdb1 to the directory /media/mp3player. So now when you connect your mp3 player to your machine you would have to issue the command mount /media/mp3player and the device would be ready for you. Of course when you are finished you would have to issue the command umount /media/mp3player in order to remove the device.
Although many may argue that mounting/unmount devices is a hassel, they will be glad for the hassel when this system keeps them from removing media before data has been written. Although it seems like a complex system, it's quite simple. And with modern distributions this has become even easier.