61

I want to understand what mounting is. It is used in different contexts and situations (directories, flash drives, network cards, etc) and I can't find resources which:

  1. Describe the mount concept;
  2. Explain the actions taken by the computer/OS/utility when a mount is performed;
  3. How and in which situations is mount used;
  4. Which features in the Linux mount command are of frequent use and some examples.
Vass
  • 5,371

3 Answers3

48

As fschnitt points out, a comprehensive answer to this would likely be a chapter in a systems administration manual, so I'll try just to sketch the basic concepts. Ask new questions if you need more detail on specific points.

In UNIX, all files in the system are organized into a single directory tree structure (as opposed to Windows, where you have a separate directory tree for each drive).

There is a "root" directory, which is denoted by /, which corresponds to the top directory on the main drive/partition (in the Windows world, this would be C:). Any other directory and file in the system can be reached from the root, by walking down sub-directories.

How can you make other drives/partitions visible to the system in such a unique tree structure? You mount them: mounting a drive/partition on a directory (e.g., /media/usb) means that the top directory on that drive/partition becomes visible as the directory being mounted. Example: if I insert a USB stick in Windows I get a new drive, e.g., F:; if in Linux I mount it on directory /media/usb, then the top directory on the USB stick (what I would see by opening the F: drive in Windows) will be visible in Linux as directory /media/usb. In this case, the /media/usb directory is called a "mount point".

Now, drives/partitions/etc. are traditionally called "(block) devices" in the UNIX world, so you always speak of mounting a device on a directory. By abuse of language, you can just say "mount this device" or "unmount that directory".

I think I've only covered your point 1., but this could get you started for more specific questions.

Check this for further reading.

  • so, when a flash drive is mounted into /media/usb, the OS maps commands like 'ls' from this directory to the flash drive to get the output? – Vass Oct 18 '10 at 14:45
  • 1
    @Vass yes, that is precisely what happens. – Riccardo Murri Oct 18 '10 at 15:16
  • @RiccardoMurri, So basically, mount is a redundant word and concept. Just use the word "link". Link the drive, Unlink the drive, The linkpoint is x. – Pacerier Aug 16 '17 at 01:03
  • @Pacerier Well, no: the term used everywhere in the Linux/UNIX world is "mount". The word "link" is used to refer to a different concept: see e.g. https://www.cyberciti.biz/tips/understanding-unixlinux-symbolic-soft-and-hard-links.html – Riccardo Murri Aug 16 '17 at 13:01
  • So, Can I mount a drive/device that is not already formatted as a particular file system? I thought mount could only attach files systems into the virtual file namespace? – Don Slowik Jan 01 '21 at 16:17
  • @DonSlowik No, you can only mount devices that have been formatted with a filesystem: mounting means that the top directory on the device becomes visibile at the mount point. (You can still operate on unformatted devices, e.g. to format them, but not mount them.) – Riccardo Murri Jan 02 '21 at 21:33
  • Right, so we don’t “mount” a device or partition, we mount a file system that has been formatted onto a particular device or partition. From man mount(1): “mount attaches a file system to the file system hierarchy...”. So we first operated on device to partition, then on the partition with mkfs. So my question becomes: it seems those devices and partitions are already part of the fs under /, how did they get those names (e.g. /dev/hda1) without having been mounted? (They did need names to be operated on.) And what’s in /proc/ likewise wasn’t a fs that was mounted at /proc... – Don Slowik Jan 03 '21 at 23:39
  • Well, that's a separate question and a valid one to ask on this site :-) – Riccardo Murri Jan 05 '21 at 11:10
28

In Unix everything is a file.

These files are organized in a tree structure, beginning at the root /.

Your filesystem or filesystems will then be mounted at the appropriate places in your / according your /etc/fstab file. This file contains information about your filesystems, which device they belong to and to which point they will get mounted to - the mountpoint.

Thats the "mount concept".

It is not limited to disks and other blockdevices, here are some examples involving mount:

  • Mount a representation of your running kernel under /proc
  • Mount a special log partition (other device, "logfriendly" filesystem) under /var/log
  • Install different systems and mount just one home directory
  • Mount remote directories for example via NFS to your system
  • Mount a image of a cd to a specific directory
echox
  • 18,103
  • then in the directory you mounted something too, you can 'cd' into there and see all the files? – Vass Oct 18 '10 at 14:43
  • Yes. You can "cd into" your mountpoint and see the files :-) – echox Oct 18 '10 at 14:48
  • can you 'mount' a directory to another directory? can you mount an input stream into a directory? what are some things other than devices you can mount? – Vass Oct 18 '10 at 17:19
  • you can't mount a directory into another, but there are hardlinks and symlinks for that. you can't mount an input stream directly, because theres no filesystem behind an input stream. you can mount it indirectly with an appropriate kernelmodule, see the last point I mentioned (cdimage). For the last point, see my examples and FuseFS. – echox Oct 18 '10 at 19:35
  • Kernel ----> Filesystem Module ----> Device / Application / Whatever – echox Oct 18 '10 at 19:36
  • @echox, So where's fstab in mac? – Pacerier Aug 16 '17 at 01:10
  • "In Unix everything is a file" sounds very profound and everyone nods when it is spoken, but what are the specific implications of this? Are there some philosophical ramifications? – Monica Heddneck Sep 22 '18 at 19:48
7

I found this resource to be helpful:

Data on a computer, as you may know, is stored in binary as a series of 1s and 0s. The way these are stored on a device and their structure is called the "filesystem". In Linux devices are referenced in /dev. Data is not actually stored on a device so you cannot access this data by going into /dev, this is because it is stored inside the filesystem on the device so you need to access these filesystems somehow. Accessing such filesystems is called "mounting" them, and in Linux (like any UNIX system) you can mount filesystems into any directory, that is, make the files stored in that filesystem accessible when you go into a certain directory. These directories are called the "mount points" of a filesystem.

libphy
  • 171
  • 1
  • 1