pwd: show mountpoint
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
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
add a comment |Â
up vote
4
down vote
favorite
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
I'm fairly sure no. A mount point isn't a symlink.
â Shadur
Sep 5 '12 at 9:55
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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
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
mount bind-mount
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
add a comment |Â
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
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
3
down vote
accepted
I think you're looking for mount -l
.
add a comment |Â
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
add a comment |Â
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);
add a comment |Â
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
add a comment |Â
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`);
New contributor
add a comment |Â
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
.
add a comment |Â
up vote
3
down vote
accepted
I think you're looking for mount -l
.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
I think you're looking for mount -l
.
I think you're looking for mount -l
.
answered Sep 5 '12 at 10:02
Jenny D
10.4k22744
10.4k22744
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Sep 6 '12 at 20:49
Gilles
518k12410351564
518k12410351564
add a comment |Â
add a comment |Â
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);
add a comment |Â
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);
add a comment |Â
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);
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);
edited Sep 9 '12 at 1:18
answered Sep 5 '12 at 10:13
daisy
28k46165297
28k46165297
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered 7 mins ago
Stéphane Chazelas
292k54543883
292k54543883
add a comment |Â
add a comment |Â
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`);
New contributor
add a comment |Â
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`);
New contributor
add a comment |Â
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`);
New contributor
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`);
New contributor
New contributor
answered 22 mins ago
DOQ
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I'm fairly sure no. A mount point isn't a symlink.
â Shadur
Sep 5 '12 at 9:55