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.
This post is part of the series: Linux Command Line
If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.
- Linux Command Line: Introduction
- Linux Command Line: ls
- Linux Command Line: cd
- Linux Command Line: mkdir
- Linux Command Line: df
- Linux Command Line: ln
- Linux Command Line: top
- Linux Command Line: mount/umount
- Linux Command Line: Cron/Crontab
- Linux Command Line: chmod
- Linux Command Line: wget
- Linux Command Line: cat
- Linux Command Line: grep
- Linux Command Line: dd
- Linux Command Line: sudo
- Linux Command Line: startx
- Linux Command Line: adduser
- Linux Command Line: at
- Linux Command Line: aterm
- Linux Command Line: nano
- Linux Command Line: hostname