Linux Command Line: mount

Linux Command Line: mount
Page content

History

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.

Final Thoughts

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.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname