Some time ago I wanted to be able to access files in a directory which was overshadowed by later mount
point. I recall finding several QAs on SE giving answers, but I recall none I've tried worked. Maybe they worked on earlier Linux kernel, I don't know. I now try to use distros with one of latest kernels (5.x now).
If indeed there is a way using "standard" tools to access part of directory tree overshadowed by mount, please write as an answer.
I have some workarounds in mind.
- Maybe there is a tool to make softlink to hardlink (inode) of directory? AFAIK standard
ln
cannot do that,ln -s
(AFAIK and by try-and-error) creates a link to a place in file tree, not inode. If where that place points to changed (via mount on top), that symlink would lead to a new place, not previous one.
Added in response to comments by @terdon:
From a user perspective (at least mine who reads man ln
etc), symlink is a type of link that operating system (including system utilities) differentiates from inodes (hardlinks). It is a link that find
would not traverse in loops.
Semi-manually read physical inode data via
dd
(before mount) and then apply it to another later (basically hard-linking). How to do that?Enable hard linking to folders in the kernel (I plan to use it rarely for special tasks, I'm aware of loop reasoning against it, but many Unixes had it AFAIK and functioned). How to do that?
P.S. might be better to split the question into several...
Added 2, ln -s
test:
$ echo 123 > 1/1/te.xt
$ ln -s 1/1 2
$ ls 2
te.xt
$ sudo mount -o loop /path/ubuntu-20.04.3-desktop-amd64.iso 1
$ ls 2 # 2 is displayed as broken link in GUI
2
Added 3, trying mount --bind
from Accessing contents on the underlying mount point path - failed
$ mount --bind 1 2
$ ls 2
1
$ sudo mount -o loop /path/ubuntu-20.04.3-desktop-amd64.iso 1
$ ls 2
boot casper dists EFI install isolinux md5sum.txt pool preseed ubuntu
Added 4: bind mount to one level up -failed same way (btw it is tmpfs system, maybe it works on ext4? have not found explanation on what you advice to do reading about --bind
in man mount
).
Added 5:
found out mount --bind
need to be executed after overshadowing mount
command.