Linux filesystem: mount point vs folder


I'd like to request the community's help in understanding the *nix concept of "mount points" versus folders. I've tried to do background reading such as this, this, and this, among others, but the concept is still fuzzy to me. I will try to ask this question such that it is not a duplicate of the first link.

Disclosure: my computing foundation has been almost entirely in a DOS/Windows environment, likely contributing to my difficulty understanding this.

First question: what is a mount point? (I've read various explanations of what it is, maybe the one given in answer to this will make the difference).

I'd like to work with a specific example, too. The following output is from a Linux box I work with:

>df -k
Filesystem                        1K-blocks      Used Available Use% Mounted on
/dev/mapper/fedora_localhost-root 239727136 215317088  12209500  95% /
devtmpfs                            8145236         0   8145236   0% /dev
tmpfs                               8166384       160   8166224   1% /dev/shm
tmpfs                               8166384       796   8165588   1% /run
tmpfs                               8166384         0   8166384   0% /sys/fs/cgroup
tmpfs                               8166384        76   8166308   1% /tmp
/dev/sda1                            487652    150127    307829  33% /boot

>ls -l /dev/mapper/fedora_localhost-root 
lrwxrwxrwx 1 root root 7 Jan  3 18:12 /dev/mapper/fedora_localhost-root -> ../dm-0

>ls -l /dev/dm-0
brw-rw---- 1 root disk 253, 0 Jan  3 18:12 /dev/dm-0

Let me try verbalize my tenuous understanding, and perhaps answerers can then understand and correct my misunderstandings

From my readings, I think Linux "makes physical devices like hard-drives available as 'block devices' which look like files located somewhere under /dev", e.g. /dev/dm-0. Is this correct?

From my readings, my understanding is that a "mount point" is like the "topmost directory" of a given partition, something like C:\ or D:\ in DOS terminology. Is that right?

One thing I don't get, then: my example shows /dev/dm-0 "mounted on" /. But isn't / the "topmost directory"? I mean every accessible folder is necessarily some subfolder of / isn't it? E.g. /home, /var, etc. are all folders "under" / because they're prefixed by /, right? What I'm getting at is: if my understanding that "a mount point is like the topmost directory of a given partition" is correct, how could you ever have more than one mount point, since the very topmost mount point / is already used up?

Related to the above paragraph: /dev/dm-0 is itself a subfolder of /. So I'm not clear how the mount point / can be the entry point to something that it's own subfolder? Something seems circular about this, and I don't understand this.

Lastly, can someone explain the difference between a mount point and a subfolder? One of the articles I read says /, /home, and /boot are all mount points. So what then is the difference between /home being a mount point versus if I had executed mkdir /home?

Thanks for any help. I'm all kinds of dazed and confused about this.

Best Answer

Windows supports drive mountpoints too (Microsoft calls them "reparse points", but the concept is the same). Since you are more familiar with Windows than with *NIX operating systems, here's a little experiment you can perform in Windows to help you understand the concept:

  1. Insert a USB flash drive into your computer.
  2. Create a new, empty folder on your desktop.
  3. Open up the Disk Management console, right-click your flash drive, and select Change Drive Letters and Paths...
  4. In the dialog that comes up, hit the Add... button.
  5. Make sure the Mount in the following empty NTFS folder: button is selected, and browse to the path of that folder you created on your desktop (e.g. C:\Users\<your profile>\Desktop\New Folder)
  6. Hit OK and OK. Now check out your desktop. You will see that the folder you created has a drive shortcut icon:

Drive shortcut icon

If you look at it from a command prompt window, you will see it as a <JUNCTION> object type:

enter image description here

Note that your flash drive now has two mount points; E: (or whatever) and that folder you created in step 2. You can remove the drive letter if you want, and you will still be able to copy files to/from it through the folder on your desktop. You can even add multiple drive letters for it if you want. This is what a mount point is: It's simply a path for you to access your drives/partitions.

Unlike Linux, Windows is representing this folder to you as some kind of oddball shortcut. Windows does this because mountpoints are a bit of a strange concept in Microsoft's world (hence your confusion). They don't even work properly in a lot of cases. But in *NIX operating systems, this is just the way things are done. A directory can be either a folder or a mountpoint in Linux, and most of the time the distinction between the two doesn't matter.

*NIX operating systems do not have a concept of drive letters. Your "root" filesystem (/) is always at the top of the tree, and is (usually but not always) mounted as your system's boot drive. This is what C:\ is to Windows. There can only ever be one root (just like there can only be one C: drive). Every other drive or partition on your system must be mounted to a path (directory) under this root. So, what would be D: or E: in Windows would be /mnt/D_Drive, /media/cdrom, or even /var, /home, or whatever in Linux.

Now this is an important thing, and is a big source of your confusion:
A device node is not the same thing as a mountpoint. Both Windows and Linux have device nodes. The difference is that Windows never shows them to you, and they do not exist as files on your hard drive the way they do in Linux.

In the command prompt screenshot above, you'll notice that the folder you created is listed as \??\Volume{GUID}\. In both Linux and Windows the raw device itself has a device node (e.g. /dev/sda1 in Linux or \??\Volume{GUID} in Windows). The mountpoint is the filesystem on that device. In Windows, you can think of drive letters (E:\ for example) as mountpoints for your drives/partitions. The only difference is that Windows never shows you the \??\Volume{GUID} device node. It only shows you mountpoints, and those mountpoints are almost always drive letters (but, as we see from the experiment above, don't have to be).

I hope this clears things up for you.

Now, go back into Disk Management and delete that mountpoint before you accidentally do something stupid, like trying to copy/move it somewhere! :-)