When mounting a partition into my CWD (mount /path/do/devxy $(pwd)
), the current shell session does not recognize it, e.g. find
does not show any contents of the partition and umount $(pwd)
succeeds despite me being in the directory (keeping it busy).
Only after explicitly entering into the directory via cd .
I can browse the files and unmounting fails.
So obviously the information on the changes in my CWD is not passed on. This behaviour is very different from e.g. entering a directory in one session and creating a file into that directory from another one. In this case find
's results are up to date.
So how does the shell determine where it is and why is the mounting not visible immediately?
Using GNU bash, version 5.0.3(1)
on debian 10
.
Considered solved: please check comments.
inode
information seems not to be updated until a proper directory change, i.e.ls -id .
changes aftercd .
- and so does the output oflsof | grep mnt
. I assumeinode
is the central property to look at here and consider this answered. – FelixJN May 31 '19 at 08:37cd .
worked is confusing. I suggest that if it did, it is because your shell is doing something other than literallychdir(".")
. You could runpython
and runimport os
,os.system("sudo mount ...")
,os.chdir(".")
,os.system("ls -id .")
. Or in another window, you could runstrace -p PID
where PID is the value ofecho $$
in the shell you run thecd .
, and it will show the exact system calls the shell makes. – sourcejedi May 31 '19 at 08:48cd ..
to go "back" after you didcd foo
even when foo is a symbolic link. It appears thatcd .
is doing something similar. – sourcejedi May 31 '19 at 08:56cd .
was not the problem, it could have beencd ../dir
,cd /path/to/dir
orcd $(cwd)
, too - I wondered about the missing update of my CWD when not "changing" paths. – FelixJN May 31 '19 at 09:00cd .
in your shell enters the new mounted directory, butls .
orfind .
do not show the new mounted directory contents. – sourcejedi May 31 '19 at 09:14cd .
should ideally be a no-op. If the system callchdir(".")
were executed, you won't see the updated (mounted) directory, but the old, underlying one. Instead, the shell sees.
and replaces it with the full path that it has kept track of internally. (Trystrace -e chdir bash -c 'cd .'
, for example). – muru May 31 '19 at 09:17find .
vs.find /path/to/dir
. Valid point, indeed. – FelixJN May 31 '19 at 09:21