I have tried bind mount to workaround a problem installing some packages with pacman
(archlinux, more about that here) on a system where /var
(as well as /home
and /usr/local
) were symlinks (across filesystems: SSD to SATA).
It looked great at first, but, as Gilles pointed out, locate
always gave multiple results for a single file, despite the PRUNE_BIND_MOUNTS = "yes"
line in /etc/updatedb.conf
.
$ locate \*/findutils-4.4.2 | xargs ls -ldiog
33816600 drwxr-xr-x 12 4096 Dec 3 00:05 /SHARED/LOCALS/Manjaro/src/findutils-4.4.2
33816600 drwxr-xr-x 12 4096 Dec 3 00:05 /usr/local/src/findutils-4.4.2
Digging a little further, I found that more complex bind mounts may be pruned correctly:
$ sudo mount --bind /SHARED/LOCALS/common/ /usr/local/common
$ findmnt | fgrep -n sdb
34:├─/SHARED/LOCALS /dev/sdb5 ext4 rw,relatime,data=ordered
35:│ └─/SHARED/LOCALS/Manjaro/common /dev/sdb5[/common] ext4 rw,relatime,data=ordered
36:├─/usr/local /dev/sdb5[/Manjaro] ext4 rw,relatime,data=ordered
37:│ └─/usr/local/common /dev/sdb5[/common] ext4 rw,relatime,data=ordered
38:├─/SHARED/HOMES /dev/sdb4 ext4 rw,relatime,data=ordered
39:├─/home /dev/sdb4[/Manjaro] ext4 rw,relatime,data=ordered
40:├─/SHARED/VARS /dev/sdb3 ext4 rw,relatime,data=ordered
41:├─/var /dev/sdb3[/Manjaro] ext4 rw,relatime,data=ordered
42:└─/opt /dev/sdb5[/opt] ext4 rw,relatime,data=ordered
$ sudo updatedb --debug-pruning 2>&1 >/dev/null | grep bind
prune_bind_mounts\000
Rebuilding bind_mount_paths:
Matching bind_mount_paths:
Skipping `/SHARED/LOCALS/Manjaro/common': bind mount
Skipping `/usr/local/common': bind mount
$ locate \*/mmedia
/SHARED/LOCALS/common/mmedia
Without the PRUNE_BIND_MOUNT option, I would have got 3 results:
$ sudo sed -i '1 s/yes/no/' /etc/updatedb.conf
$ sudo updatedb --debug-pruning 2>&1 >/dev/null | grep bind
prune_bind_mounts\000
$ locate \*/mmedia
/SHARED/LOCALS/Manjaro/common/mmedia
/SHARED/LOCALS/common/mmedia
/usr/local/common/mmedia
$ sudo sed -i '1 s/no/yes/' /etc/updatedb.conf
Another issue with bind mounts:
Of course, one can manually add bind mounts (mounpoint or target) to
PRUNEPATHS
in /etc/updatedb.conf
.
Also, mountpoint
and various stat
commands or functions can be used in tools to improve filesystem traversal as proposed here