2

I have a directory /dir1, /dir1/sdir2. what will happen if I issue the below command:

mount --bind /dir1 /dir1/sdir2

I thought it will create a directory loop but the loop ends at level 1.

Can anyone kindly explain to me why the above command does not create a directory loop?

1 Answer 1

1

In your bind mount, mounts inside the original directory where not propagated further. To do that, use --rbind. From the mount manpage:

Bind mount operation
   Remount part of the file hierarchy somewhere else.  The call is:

          mount --bind olddir newdir

   [...]

   The bind mount call attaches only (part of) a single filesystem, not
   possible submounts.  The entire file hierarchy including submounts is
   attached a second place by using:

          mount --rbind olddir newdir

However, this will propagate the submounts only once, so there's still no loop:

% mkdir -p foo/bar
% sudo mount --rbind foo foo/bar
% ls foo
bar
% ls foo/bar
bar
% ls foo/bar/bar

I don't think there's a way to propagate mounts recursively and infinitely.

3
  • What will happen to /dir1/sdir2 mount point after level 1, will that become a normal directory ? Dec 6, 2019 at 12:24
  • If I think each directory like a pointer then it shoud loop right? Am i missing anything? Dec 6, 2019 at 12:25
  • What will it loop to? The directory is still the directory, when you mount something on it, that doesn't change the contents of the directory - it just puts a layer on top. That layer isn't carried over everywhere the directory goes, though.
    – muru
    Dec 6, 2019 at 13:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .