LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Mounting two partitions to the same dir, how programs can keep apart (https://www.linuxquestions.org/questions/linux-software-2/mounting-two-partitions-to-the-same-dir-how-programs-can-keep-apart-761351/)

zhjim 10-12-2009 07:40 AM

Mounting two partitions to the same dir, how programs can keep apart
 
Hi folks,

by accident I mounted a second partition to the same directory (/mnt). In the meanwhile a earlier started program wrote to this first mounted partition. After the second partition got mounted another program accessed this one.
As far as I can tell both programs where happy and did their job but my restless brain could not find a hint how the programs knew which partition to actually use. Only one I could imagine was that they had this information at startup and did not ask again.

Anyone around here who can shed some light or provide a link to dig into?

pixellany 10-12-2009 08:41 AM

First, note a fine point: You mount (connect) filesystems to mount points. You cannot mount a partition that is not formatted.

You can mount 2 different filesystems to the same mount point---the system will always use the last one mounted. Try some experiments to see.

zhjim 10-12-2009 09:42 AM

Quote:

Originally Posted by pixellany (Post 3716421)
First, note a fine point: You mount (connect) filesystems to mount points. You cannot mount a partition that is not formatted.

Thanks for the hint I hope I'll remember.

I did some minor test to see how partitions overlap but did not went very far. I have some testing in my head.

1.) Mount first filesystem
2.) start an scp copy of some files say 100MB per file
3.) mount second filesystem
4.) look where the files get written to

I post back on the outcome tomorrow.

(in first draft I wrote "mount first partition" again. *oh brain* ;))

zhjim 10-13-2009 03:14 AM

Did some experiments today. Also I did not get any understanding of the reason why the output is illuminating

The route I went
1.) mounted /dev/sdb10 /tmp/holy
2.) Used this little script
Code:

for i in $(seq 1 10); do touch /tmp/holy/$i; sleep 2; done
3.) waited some secs and mounted /dev/sdb11 /tmp/holy
4.) waited some; umounted /dev/sdb11

Outcome was that some of the files where on /dev/sdb10 and some on /dev/sdb11...

While trying this with an scp download the big file just remained on the first mounted filesystem...

So the conclusion to this is as soon as a program is run the mounts are fixed. Now to find out why and where this information is stored in the system.

pixellany 10-13-2009 03:33 AM

I'm missing something....
If you omit the part about the scp download, then the conclusion is that the mounting can be changed while a program is running.

Note that "can" does not equal "good idea".......:) In this case, I would think that your example would eventually give unpredictable results.

But I thought the point was just to illustrate how overlapping mounts work. If you just do the mounts alternated with copying (or touching) files, I think you'll find very predictable behavior.

zhjim 10-13-2009 06:19 AM

Quote:

Originally Posted by pixellany (Post 3717374)
I'm missing something....
If you omit the part about the scp download, then the conclusion is that the mounting can be changed while a program is running.

But thats just the question: when does the program get notice about the change. What I found out is not while it already has an open file(handle). So every time a new handle is aquired the filesysteam is read.. I'm not seeing the woods for the trees. Gotta dig on some more filesystem and kernel internals :study:

Quote:

Originally Posted by pixellany (Post 3717374)
Note that "can" does not equal "good idea".......:) In this case, I would think that your example would eventually give unpredictable results.

x x x
(sign here)


Quote:

Originally Posted by pixellany (Post 3717374)
But I thought the point was just to illustrate how overlapping mounts work. If you just do the mounts alternated with copying (or touching) files, I think you'll find very predictable behavior.

Hm actually I dont know what I wanted to show :D
It just another amazing thing I found out by accident. It sure allows for some fun


All times are GMT -5. The time now is 09:36 AM.