Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I attempt to mount a folder that already has files in it, does linux give me an error message or go ahead and show both the mounted filesystem and the files that were already in the folder?

share|improve this question
1  
Could always try it out with some test files, no? –  Chris Oct 18 '10 at 14:35
    
I would of if I could. It just worked out that I didn't have anything to test with. I tried unmounting and mounting the drive in question but the results were inconclusive because they both had the same files. –  shady Oct 18 '10 at 14:39

2 Answers 2

up vote 11 down vote accepted

It will just be mounted, and the files disappear, coming back when the folder is umounted.

share|improve this answer
    
What do you mean by disappear? They continue to exist on the server and are just not shown or are the deleted? –  shady Oct 18 '10 at 14:08
    
I'll go have a quick check, but I think they are deleted. –  Azz Oct 18 '10 at 14:10
    
My bad, they go away while it's mounted, but come back when it's umounted. –  Azz Oct 18 '10 at 14:11
7  
+1 The files are simply invisible while the directory is mounted "over" them. They never really go away, the are just inaccessible... –  sleske Oct 18 '10 at 14:50
6  
It works like a stack, if you mount something else, it hides the previous content. When you unmount, the previous stuff becomes visible again. –  vtest Oct 18 '10 at 15:09

When you mount a filesystem on a directory /mount-point, you can no longer access files under /mount-point directly. They still exist, but /mount-point now refers to the root of the mounted filesystem, not to the directory that served as a mount point, so the contents of this directory cannot be accessed, at least in this way. For example:

# touch /mount-point/somefile
# ls /mount-point/somefile
/mount-point/somefile
# mount /dev/something /mount-point
# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory

There are ways to get a merged view of the mounted filesystem and the data that was already present, but you need an extra layer called a union filesystem.

Under Linux, there is a way to see the hidden files. You can use mount --bind to get another view of the filesystem where the mount point is. For example

mount --bind / /other-root-view

You'll see all the files in the root filesystem under /other-root-view.

# cat /other-root-view/etc/hostname 
darkstar

In particular, /mount-point will now be accessible as /other-root-view, and since /other-root-view/mount-point is not a mount point, you can see its contents there:

# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory
# ls /other-root-view/mount-point/somefile
/other-root-view/mount-point/somefile
share|improve this answer
4  
Gilles, this answer just saved my butt when I needed to get some asterisk recordings that got saved underneath an NSF mount point! I always thought --bind had the same perspective as the user. Thank you! –  andyortlieb Jul 19 '11 at 14:55
    
Best and most thorough explanation :) –  matiu Jan 30 at 5:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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