pwd: show mountpoint

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
1












I have mounted a directory to another directory using mount --bind so that an sftp user of my server can access this directory.



mount --bind /path/share /path/home/user/stuff


I have put this in /etc/fstab and it is working great.



If I cd into the mounted directory and do pwd, it seems as if the directory is actually, physically there:



/path/home/user/stuff/share


Is there a command that shows where the 'original' directory is located
(just as symlinks: when you do ls -fsl you see the original path)?










share|improve this question























  • I'm fairly sure no. A mount point isn't a symlink.
    – Shadur
    Sep 5 '12 at 9:55














up vote
4
down vote

favorite
1












I have mounted a directory to another directory using mount --bind so that an sftp user of my server can access this directory.



mount --bind /path/share /path/home/user/stuff


I have put this in /etc/fstab and it is working great.



If I cd into the mounted directory and do pwd, it seems as if the directory is actually, physically there:



/path/home/user/stuff/share


Is there a command that shows where the 'original' directory is located
(just as symlinks: when you do ls -fsl you see the original path)?










share|improve this question























  • I'm fairly sure no. A mount point isn't a symlink.
    – Shadur
    Sep 5 '12 at 9:55












up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I have mounted a directory to another directory using mount --bind so that an sftp user of my server can access this directory.



mount --bind /path/share /path/home/user/stuff


I have put this in /etc/fstab and it is working great.



If I cd into the mounted directory and do pwd, it seems as if the directory is actually, physically there:



/path/home/user/stuff/share


Is there a command that shows where the 'original' directory is located
(just as symlinks: when you do ls -fsl you see the original path)?










share|improve this question















I have mounted a directory to another directory using mount --bind so that an sftp user of my server can access this directory.



mount --bind /path/share /path/home/user/stuff


I have put this in /etc/fstab and it is working great.



If I cd into the mounted directory and do pwd, it seems as if the directory is actually, physically there:



/path/home/user/stuff/share


Is there a command that shows where the 'original' directory is located
(just as symlinks: when you do ls -fsl you see the original path)?







mount bind-mount






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 5 '15 at 23:11









Gilles

518k12410351564




518k12410351564










asked Sep 5 '12 at 9:16









Vincent

1,04841524




1,04841524











  • I'm fairly sure no. A mount point isn't a symlink.
    – Shadur
    Sep 5 '12 at 9:55
















  • I'm fairly sure no. A mount point isn't a symlink.
    – Shadur
    Sep 5 '12 at 9:55















I'm fairly sure no. A mount point isn't a symlink.
– Shadur
Sep 5 '12 at 9:55




I'm fairly sure no. A mount point isn't a symlink.
– Shadur
Sep 5 '12 at 9:55










5 Answers
5






active

oldest

votes

















up vote
3
down vote



accepted










I think you're looking for mount -l.






share|improve this answer



























    up vote
    2
    down vote













    Yes, the directory is there, because you mounted it there. mount --bind tells the kernel to use an existing mount and attach it to another mount point. As far as the kernel is concerned,



    mount /dev/something /path/share
    mount --bind /path/share /path/home/user/stuff


    and



    mount /dev/something /path/home/user/stuff
    mount --bind /path/share /path/home/user/stuff


    are the same thing. There are two ways to distinguish them:



    • If /path/share is not a mount point (i.e. it's part of a larger filesystem mounted at /path or /), you can tell the bind mount because it's not at the root of the filesystem.

    • The mount program records its actions in /etc/mtab.

    The df command reads /etc/mtab, so if a directory is on a filesystem that's been mounted with the bind option, you can see what the original path was with



    df -P /path/to/file | awk 'NR==2 print $1'


    (first field of the second line). Note that this information isn't always reliable, for example it's possible that the original filesystem has been unmounted and nothing, or something else, is now mounted at this location, as in



    mount /dev/something /path/share
    mount --bind /path/share /path/home/user/stuff
    unmount /dev/something
    mount /dev/somethingelse /path/share





    share|improve this answer



























      up vote
      1
      down vote













      I checked source code of df, and made a similar script that will find the original path,



      e.g you bind /tmp/a to /tmp/b,



      And you launch my script with perl script.pl /tmp/b/what/ever/deep/inside, you will find /tmp/a



      #!/usr/bin/perl

      use strict;
      use warnings;
      use File::Basename;

      sub findmnt
      ' or die;
      while (<$fh>)

      return $1 if ($_ =~ qq(.*) on $path type )

      ;

      if ($#ARGV lt 0)

      die 'Usage: ', $0, ' /path/to/dir', "n";


      my $mntpath = $ARGV[0];
      while ($mntpath ne '/')

      my $origpath = findmnt $mntpath;
      if ($origpath ne '')

      print 'Original path: ', $origpath, "n";
      last;


      $mntpath = dirname ($mntpath);






      share|improve this answer





























        up vote
        1
        down vote













        On Linux, you can now use findmnt (from util-linux) for that:



        ~$ sudo mount --bind /usr/local mnt
        ~$ cd mnt/bin
        ~/mnt/bin$ pwd
        /home/stephane/mnt/bin
        ~/mnt/bin$ findmnt -T .
        TARGET SOURCE FSTYPE OPTIONS
        /home/stephane/mnt /dev/mapper/VG-LV[/usr/local] ext4 rw,noatime,discard,errors=remount-ro,data=ordered




        share



























          up vote
          0
          down vote













          Based on daisy's response, how about...



          use strict;
          use warnings;
          use File::Basename;

          my $mntpath = $ARGV[0] or die "Missing required parameter <pathname>n";
          $mntpath = dirname ($mntpath) while (! grep / on $mntpath type /, `mount`);





          share|improve this answer








          New contributor




          DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f47212%2fpwd-show-mountpoint%23new-answer', 'question_page');

            );

            Post as a guest






























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            I think you're looking for mount -l.






            share|improve this answer
























              up vote
              3
              down vote



              accepted










              I think you're looking for mount -l.






              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                I think you're looking for mount -l.






                share|improve this answer












                I think you're looking for mount -l.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 5 '12 at 10:02









                Jenny D

                10.4k22744




                10.4k22744






















                    up vote
                    2
                    down vote













                    Yes, the directory is there, because you mounted it there. mount --bind tells the kernel to use an existing mount and attach it to another mount point. As far as the kernel is concerned,



                    mount /dev/something /path/share
                    mount --bind /path/share /path/home/user/stuff


                    and



                    mount /dev/something /path/home/user/stuff
                    mount --bind /path/share /path/home/user/stuff


                    are the same thing. There are two ways to distinguish them:



                    • If /path/share is not a mount point (i.e. it's part of a larger filesystem mounted at /path or /), you can tell the bind mount because it's not at the root of the filesystem.

                    • The mount program records its actions in /etc/mtab.

                    The df command reads /etc/mtab, so if a directory is on a filesystem that's been mounted with the bind option, you can see what the original path was with



                    df -P /path/to/file | awk 'NR==2 print $1'


                    (first field of the second line). Note that this information isn't always reliable, for example it's possible that the original filesystem has been unmounted and nothing, or something else, is now mounted at this location, as in



                    mount /dev/something /path/share
                    mount --bind /path/share /path/home/user/stuff
                    unmount /dev/something
                    mount /dev/somethingelse /path/share





                    share|improve this answer
























                      up vote
                      2
                      down vote













                      Yes, the directory is there, because you mounted it there. mount --bind tells the kernel to use an existing mount and attach it to another mount point. As far as the kernel is concerned,



                      mount /dev/something /path/share
                      mount --bind /path/share /path/home/user/stuff


                      and



                      mount /dev/something /path/home/user/stuff
                      mount --bind /path/share /path/home/user/stuff


                      are the same thing. There are two ways to distinguish them:



                      • If /path/share is not a mount point (i.e. it's part of a larger filesystem mounted at /path or /), you can tell the bind mount because it's not at the root of the filesystem.

                      • The mount program records its actions in /etc/mtab.

                      The df command reads /etc/mtab, so if a directory is on a filesystem that's been mounted with the bind option, you can see what the original path was with



                      df -P /path/to/file | awk 'NR==2 print $1'


                      (first field of the second line). Note that this information isn't always reliable, for example it's possible that the original filesystem has been unmounted and nothing, or something else, is now mounted at this location, as in



                      mount /dev/something /path/share
                      mount --bind /path/share /path/home/user/stuff
                      unmount /dev/something
                      mount /dev/somethingelse /path/share





                      share|improve this answer






















                        up vote
                        2
                        down vote










                        up vote
                        2
                        down vote









                        Yes, the directory is there, because you mounted it there. mount --bind tells the kernel to use an existing mount and attach it to another mount point. As far as the kernel is concerned,



                        mount /dev/something /path/share
                        mount --bind /path/share /path/home/user/stuff


                        and



                        mount /dev/something /path/home/user/stuff
                        mount --bind /path/share /path/home/user/stuff


                        are the same thing. There are two ways to distinguish them:



                        • If /path/share is not a mount point (i.e. it's part of a larger filesystem mounted at /path or /), you can tell the bind mount because it's not at the root of the filesystem.

                        • The mount program records its actions in /etc/mtab.

                        The df command reads /etc/mtab, so if a directory is on a filesystem that's been mounted with the bind option, you can see what the original path was with



                        df -P /path/to/file | awk 'NR==2 print $1'


                        (first field of the second line). Note that this information isn't always reliable, for example it's possible that the original filesystem has been unmounted and nothing, or something else, is now mounted at this location, as in



                        mount /dev/something /path/share
                        mount --bind /path/share /path/home/user/stuff
                        unmount /dev/something
                        mount /dev/somethingelse /path/share





                        share|improve this answer












                        Yes, the directory is there, because you mounted it there. mount --bind tells the kernel to use an existing mount and attach it to another mount point. As far as the kernel is concerned,



                        mount /dev/something /path/share
                        mount --bind /path/share /path/home/user/stuff


                        and



                        mount /dev/something /path/home/user/stuff
                        mount --bind /path/share /path/home/user/stuff


                        are the same thing. There are two ways to distinguish them:



                        • If /path/share is not a mount point (i.e. it's part of a larger filesystem mounted at /path or /), you can tell the bind mount because it's not at the root of the filesystem.

                        • The mount program records its actions in /etc/mtab.

                        The df command reads /etc/mtab, so if a directory is on a filesystem that's been mounted with the bind option, you can see what the original path was with



                        df -P /path/to/file | awk 'NR==2 print $1'


                        (first field of the second line). Note that this information isn't always reliable, for example it's possible that the original filesystem has been unmounted and nothing, or something else, is now mounted at this location, as in



                        mount /dev/something /path/share
                        mount --bind /path/share /path/home/user/stuff
                        unmount /dev/something
                        mount /dev/somethingelse /path/share






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 6 '12 at 20:49









                        Gilles

                        518k12410351564




                        518k12410351564




















                            up vote
                            1
                            down vote













                            I checked source code of df, and made a similar script that will find the original path,



                            e.g you bind /tmp/a to /tmp/b,



                            And you launch my script with perl script.pl /tmp/b/what/ever/deep/inside, you will find /tmp/a



                            #!/usr/bin/perl

                            use strict;
                            use warnings;
                            use File::Basename;

                            sub findmnt
                            ' or die;
                            while (<$fh>)

                            return $1 if ($_ =~ qq(.*) on $path type )

                            ;

                            if ($#ARGV lt 0)

                            die 'Usage: ', $0, ' /path/to/dir', "n";


                            my $mntpath = $ARGV[0];
                            while ($mntpath ne '/')

                            my $origpath = findmnt $mntpath;
                            if ($origpath ne '')

                            print 'Original path: ', $origpath, "n";
                            last;


                            $mntpath = dirname ($mntpath);






                            share|improve this answer


























                              up vote
                              1
                              down vote













                              I checked source code of df, and made a similar script that will find the original path,



                              e.g you bind /tmp/a to /tmp/b,



                              And you launch my script with perl script.pl /tmp/b/what/ever/deep/inside, you will find /tmp/a



                              #!/usr/bin/perl

                              use strict;
                              use warnings;
                              use File::Basename;

                              sub findmnt
                              ' or die;
                              while (<$fh>)

                              return $1 if ($_ =~ qq(.*) on $path type )

                              ;

                              if ($#ARGV lt 0)

                              die 'Usage: ', $0, ' /path/to/dir', "n";


                              my $mntpath = $ARGV[0];
                              while ($mntpath ne '/')

                              my $origpath = findmnt $mntpath;
                              if ($origpath ne '')

                              print 'Original path: ', $origpath, "n";
                              last;


                              $mntpath = dirname ($mntpath);






                              share|improve this answer
























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                I checked source code of df, and made a similar script that will find the original path,



                                e.g you bind /tmp/a to /tmp/b,



                                And you launch my script with perl script.pl /tmp/b/what/ever/deep/inside, you will find /tmp/a



                                #!/usr/bin/perl

                                use strict;
                                use warnings;
                                use File::Basename;

                                sub findmnt
                                ' or die;
                                while (<$fh>)

                                return $1 if ($_ =~ qq(.*) on $path type )

                                ;

                                if ($#ARGV lt 0)

                                die 'Usage: ', $0, ' /path/to/dir', "n";


                                my $mntpath = $ARGV[0];
                                while ($mntpath ne '/')

                                my $origpath = findmnt $mntpath;
                                if ($origpath ne '')

                                print 'Original path: ', $origpath, "n";
                                last;


                                $mntpath = dirname ($mntpath);






                                share|improve this answer














                                I checked source code of df, and made a similar script that will find the original path,



                                e.g you bind /tmp/a to /tmp/b,



                                And you launch my script with perl script.pl /tmp/b/what/ever/deep/inside, you will find /tmp/a



                                #!/usr/bin/perl

                                use strict;
                                use warnings;
                                use File::Basename;

                                sub findmnt
                                ' or die;
                                while (<$fh>)

                                return $1 if ($_ =~ qq(.*) on $path type )

                                ;

                                if ($#ARGV lt 0)

                                die 'Usage: ', $0, ' /path/to/dir', "n";


                                my $mntpath = $ARGV[0];
                                while ($mntpath ne '/')

                                my $origpath = findmnt $mntpath;
                                if ($origpath ne '')

                                print 'Original path: ', $origpath, "n";
                                last;


                                $mntpath = dirname ($mntpath);







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Sep 9 '12 at 1:18

























                                answered Sep 5 '12 at 10:13









                                daisy

                                28k46165297




                                28k46165297




















                                    up vote
                                    1
                                    down vote













                                    On Linux, you can now use findmnt (from util-linux) for that:



                                    ~$ sudo mount --bind /usr/local mnt
                                    ~$ cd mnt/bin
                                    ~/mnt/bin$ pwd
                                    /home/stephane/mnt/bin
                                    ~/mnt/bin$ findmnt -T .
                                    TARGET SOURCE FSTYPE OPTIONS
                                    /home/stephane/mnt /dev/mapper/VG-LV[/usr/local] ext4 rw,noatime,discard,errors=remount-ro,data=ordered




                                    share
























                                      up vote
                                      1
                                      down vote













                                      On Linux, you can now use findmnt (from util-linux) for that:



                                      ~$ sudo mount --bind /usr/local mnt
                                      ~$ cd mnt/bin
                                      ~/mnt/bin$ pwd
                                      /home/stephane/mnt/bin
                                      ~/mnt/bin$ findmnt -T .
                                      TARGET SOURCE FSTYPE OPTIONS
                                      /home/stephane/mnt /dev/mapper/VG-LV[/usr/local] ext4 rw,noatime,discard,errors=remount-ro,data=ordered




                                      share






















                                        up vote
                                        1
                                        down vote










                                        up vote
                                        1
                                        down vote









                                        On Linux, you can now use findmnt (from util-linux) for that:



                                        ~$ sudo mount --bind /usr/local mnt
                                        ~$ cd mnt/bin
                                        ~/mnt/bin$ pwd
                                        /home/stephane/mnt/bin
                                        ~/mnt/bin$ findmnt -T .
                                        TARGET SOURCE FSTYPE OPTIONS
                                        /home/stephane/mnt /dev/mapper/VG-LV[/usr/local] ext4 rw,noatime,discard,errors=remount-ro,data=ordered




                                        share












                                        On Linux, you can now use findmnt (from util-linux) for that:



                                        ~$ sudo mount --bind /usr/local mnt
                                        ~$ cd mnt/bin
                                        ~/mnt/bin$ pwd
                                        /home/stephane/mnt/bin
                                        ~/mnt/bin$ findmnt -T .
                                        TARGET SOURCE FSTYPE OPTIONS
                                        /home/stephane/mnt /dev/mapper/VG-LV[/usr/local] ext4 rw,noatime,discard,errors=remount-ro,data=ordered





                                        share











                                        share


                                        share










                                        answered 7 mins ago









                                        Stéphane Chazelas

                                        292k54543883




                                        292k54543883




















                                            up vote
                                            0
                                            down vote













                                            Based on daisy's response, how about...



                                            use strict;
                                            use warnings;
                                            use File::Basename;

                                            my $mntpath = $ARGV[0] or die "Missing required parameter <pathname>n";
                                            $mntpath = dirname ($mntpath) while (! grep / on $mntpath type /, `mount`);





                                            share|improve this answer








                                            New contributor




                                            DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                            Check out our Code of Conduct.





















                                              up vote
                                              0
                                              down vote













                                              Based on daisy's response, how about...



                                              use strict;
                                              use warnings;
                                              use File::Basename;

                                              my $mntpath = $ARGV[0] or die "Missing required parameter <pathname>n";
                                              $mntpath = dirname ($mntpath) while (! grep / on $mntpath type /, `mount`);





                                              share|improve this answer








                                              New contributor




                                              DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.



















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                Based on daisy's response, how about...



                                                use strict;
                                                use warnings;
                                                use File::Basename;

                                                my $mntpath = $ARGV[0] or die "Missing required parameter <pathname>n";
                                                $mntpath = dirname ($mntpath) while (! grep / on $mntpath type /, `mount`);





                                                share|improve this answer








                                                New contributor




                                                DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.









                                                Based on daisy's response, how about...



                                                use strict;
                                                use warnings;
                                                use File::Basename;

                                                my $mntpath = $ARGV[0] or die "Missing required parameter <pathname>n";
                                                $mntpath = dirname ($mntpath) while (! grep / on $mntpath type /, `mount`);






                                                share|improve this answer








                                                New contributor




                                                DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.









                                                share|improve this answer



                                                share|improve this answer






                                                New contributor




                                                DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.









                                                answered 22 mins ago









                                                DOQ

                                                1




                                                1




                                                New contributor




                                                DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.





                                                New contributor





                                                DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.






                                                DOQ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                Check out our Code of Conduct.



























                                                     

                                                    draft saved


                                                    draft discarded















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f47212%2fpwd-show-mountpoint%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest













































































                                                    Popular posts from this blog

                                                    How to check contact read email or not when send email to Individual?

                                                    Displaying single band from multi-band raster using QGIS

                                                    How many registers does an x86_64 CPU actually have?