4

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.

4
  • /boot the the directory used for mounting the boot (ESD, EFI, etc.) partition. It is mounted after the system boots.
    – Joseph
    Jan 4, 2017 at 19:08
  • A drive maybe mounted to any real blank folder or subfolder. Mounting to folders with contents can be done, but I don't recommend it. mount /dev/sda1 /here/there is just as valid as mount /dev/sda1 /scooby
    – cybernard
    Jan 4, 2017 at 19:12
  • Folders are a windows idea, forget them. As for directories, well in linux everything is a file, and so it can exist in a directory. Also, there's nothing inhertiently wrong with circular links, you can have a link in /link that goes to /; Linux allows for this, accept it, move on. Jan 4, 2017 at 20:05
  • 1
    On Windows, you can also mount in folders. There are some restrictions, but the result is the same.
    – Daniel B
    Jan 4, 2017 at 21:58

5 Answers 5

8

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! :-)

9
  • "A directory can be either a folder or a mountpoint in Linux" - this clears up a lot of my confusion, thank you. The follow-up question I would then ask is: if / and /home are mount points to two different physical hard drives, isn't is ambiguous that the directory /home isn't really a subdirectory of / even though /home is prefixed by /? I.e. if you did mkdir /foo and mkdir /home/foo, the folder is on different hard drives, even though they appear "under" /. How do *NIX users know where they're working if directories and mount points are sort of the same?
    – StoneThrow
    Jan 4, 2017 at 23:19
  • If you had a directory called /home and a mountpoint called /home, then the mountpoint would take precedence. If '/home' were a mountpoint to a different drive, then anything you place inside the /home directory would disappear once you unmounted the drive. Likewise, if you created a directory called /home/bar and then mounted a drive to /home, /home/bar would disappear, and you would only see /home/foo while that drive was mounted. Windows resolves this ambiguity by only allowing you to use an empty directory as a mountpoint, but Linux/UNIX doesn't care.
    – Wes Sayeed
    Jan 4, 2017 at 23:58
  • And actually, /home is a directory under / just like in the directory on the desktop in WIndows experiment I outlined above. The directory must exist before you can mount anything there. It only becomes a mountpoint when something is mounted there. Otherwise, it reverts to a regular ol' directory.
    – Wes Sayeed
    Jan 5, 2017 at 0:02
  • So if I understand correctly, even though all directories are hierarchically "under" /, i.e. the root mount point, because any of those directories could be a mount point, there is no implied hierarchical relationship between "where they really point to" - is that correct? Sorry if this is a dumb question, but why isn't it confusing to every *NIX user to know whether a directory is a "regular ol' directory" or a mount point? How do you know "where you are" when you are cding around between folders? Don't you need to know what drive/partition you are really on?
    – StoneThrow
    Jan 5, 2017 at 0:13
  • "there is no implied hierarchical relationship between 'where they really point to' - is that correct?" Yes, you are exactly correct. If an application expects its log files to be in /var/logs, then it doesn't matter if /var is on your boot drive or some remote server on the internet. As long as the file exists and is accessible when the program expects it to be, the program doesn't care. This is in contrast to Windows, where programs tend to freak out when they find out a file is on the network instead of on your hard drive.
    – Wes Sayeed
    Jan 5, 2017 at 0:22
3
Wrote this as a comment, realised I could expand it into a full blown answer.

Folders are a windows idea, forget them. As for directories, well in linux everything is a file, and so it can exist in a directory. Also, there's nothing inherently wrong with circular links, you can have a link in /link that goes to /; Linux allows for this, accept it, move on

A mount point, is the point at which a mounted device is accessable.

Your / 'root' never moves, it's always / but everything else can be anywhere you'd want it to be. (There are certain standards we try and stick to, detailed in the LSFH documentation.)

Once you have /, you can then mount other devices within this 'space'. Normally you'd have a swap drive/file which exists under some obscure path taken care of by the kernel

You might have an entire drive dedicated to /home - so this would be it's mount point and then you might have /usr and /tmp on their own drives as well, each of these being a mount point too.

You can imagine the physical devices exist outside of /, and the stuff under /dev is merely imaginary shortcuts to it if that makes you feel better.

3
  • "You might have an entire drive dedicated to /home - so this would be it's mount point and then you might have /usr and /tmp on their own drives as well". Does this mean if I did mkdir /home/foo and mkdir /usr/foo I would have made foo directories on each of the two drives dedicated to /home and /usr, respectively?
    – StoneThrow
    Jan 4, 2017 at 20:45
  • @StoneThrow "…I would have made foo directories on each of the two drives dedicated to /home and /usr, respectively?" – That's right. Jan 4, 2017 at 21:45
  • 1
    "Folders are a windows idea, forget them." - That's not a good way to put it. In fact, I feel it's the worst way. Folders are a superset, so let's not forget about them. There are virtual folders, yes, but I don't think the OP's confusion is related to that.
    – Daniel B
    Jan 4, 2017 at 22:03
2

General rule: having a directory you can make it a mountpoint by mounting something at it. The original directory content (if any; it's a good practice to use empty directories for mountpoints) is from now on inaccessible, because some other filesystem is overlaid there.

E.g. if your HDD was D:\ in Windows and there was D:\data\a1\ folder, you can mount it under Linux in /mnt/foo/ and immediately have /mnt/foo/data/a1/. Mounting in /bar/baz/ instead will allow you to reach the same a1 directory as /bar/baz/data/a1/.

A subdirectory somewhere inside this newly mounted filesystem (like /bar/baz/data/a1/) may become a mountpoint for something else if you wish, no general restriction here.

At the beginning you have / available. You mount your root filesystem there. It includes (among others) some empty directories intended to be mountpoints for other filesystems. This way you build your directory tree – by overlying various filesystems at certain mountpoints in the right order.

0

On Windows, when you have different partitions or whole drives with a filesystem that the OS recognizes, they get a drive letter assigned (D:, E:, etc). On Unix, you have one filesystem which is mounted as root and the rest of them is accessible through mountpoints. Once is mounted you access the drive as a folder of the root filesystem. The mountpoint folder must exist on the root filesystem before you mount another filesystem there. Because unix tends to implement all as a general solution, you can mount a windows share, an .iso image or a temporal filesystem (like a DOS ramdrive) on a mountpoint and once is mounted is transparent for the user.

Note: I know this is a slightly unnaccurate description, but is the way I would explained it to me when a I was a Windows user.

0

Think of any / (slash) as a mount-point.

mount is a method with various meanings of mount something on a mount point. 'Something' can be actual hardware: a usb-disk or one partition of a disk, for instance. So an administrator can knit together the one overall structure ordinary users see. An administrator may also allow users to mount privately owned memory at selected mount points.

A mount-point may also be seen as a folder, e.g. in a user's home directory and its subtrees. A user with administrator's privileges may mount a folder on other mountpoints in the home directory. The same data will in that case be available in different ways. The mount method must be invoked with appropriate options, of course.

Users are advised that a mount-point is empty when seen as a subfolder. If the mount-point is non-empty, a mount will hide it until the mount is undone with a umount command.

Note that a path-elements, .. , pointing upwards through an actual mount point should depend on its actual origin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.