Linux filesystem: mount point vs folder?
Solution 1
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:
- Insert a USB flash drive into your computer.
- Create a new, empty folder on your desktop.
- Open up the Disk Management console, right-click your flash drive, and select
Change Drive Letters and Paths...
- In the dialog that comes up, hit the
Add...
button. - 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
) - Hit OK and OK. Now check out your desktop. You will see that the folder you created has a drive shortcut icon:
If you look at it from a command prompt window, you will see it as a <JUNCTION>
object type:
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! :-)
Solution 2
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.
Solution 3
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.
Related videos on Youtube
StoneThrow
Updated on September 18, 2022Comments
-
StoneThrow over 1 year
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:\
orD:\
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 executedmkdir /home
?Thanks for any help. I'm all kinds of dazed and confused about this.
-
Joseph over 7 years
/boot
the the directory used for mounting the boot (ESD, EFI, etc.) partition. It is mounted after the system boots. -
cybernard over 7 yearsA 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
-
djsmiley2kStaysInside over 7 yearsFolders 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.
-
Daniel B over 7 yearsOn Windows, you can also mount in folders. There are some restrictions, but the result is the same.
-
-
StoneThrow over 7 years"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
andmkdir /usr/foo
I would have madefoo
directories on each of the two drives dedicated to/home
and/usr
, respectively? -
Kamil Maciorowski over 7 years@StoneThrow "…I would have made foo directories on each of the two drives dedicated to
/home
and/usr
, respectively?" – That's right. -
Daniel B over 7 years"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.
-
StoneThrow over 7 years"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 didmkdir /foo
andmkdir /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? -
Wes Sayeed over 7 yearsIf 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 over 7 yearsAnd 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. -
StoneThrow over 7 yearsSo 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 arecd
ing around between folders? Don't you need to know what drive/partition you are really on? -
Wes Sayeed over 7 years"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. -
StoneThrow over 7 yearsFascinating. Linux is so deep and daunting, but your answer and follow-up comments were great shedding light on this part of the OS for me. Thank you.
-
Murray Jensen almost 7 yearsJust to complicate matters a little,
/
is per process i.e. processes can have a different idea of where/
is (check out thechroot
system call) -
Eryk Sun over 4 yearsA DOS drive links to the volume device itself (except mapped and subst drives), which differs from a Unix filesystem mount point. There's a linked pair of directories (per-logon and global) in the object namespace where the system creates symlinks to devices. It's accessed as "\\?\", "\\.\" or (NT only) "\??\". For example, "\\?\C:" might link to "\Device\HarddiskVolume2". Unlike Unix, a device has its own namespace, which may be mounted by a filesystem device that takes over the job of parsing the remaining path, so the true Unix-like mount point is "C:\" -- as if "/dev/sda1/" worked in Unix.
-
Eryk Sun over 4 yearsThe "Volume{GUID}" name links to the device, the same as the drive-letter (if any). It's created to support folder mount points. A mount point is one type of filesystem reparse point among many (support for new types is added by filesystem filter drivers). This type of reparse point implements mount-point behavior, such as namespace grafting when traversed by relative symlinks. It can function as a volume mount point or as a bind-like mount point to a subdirectory on the same or another local volume. Importantly, for a volume mount it reparses to the root directory, not the device itself.