1

Currently I'm trying to migrate from mlocate to plocate.

I'm using mlocate in my script (note: locate is aliased to either mlocate or plocate depending which one I've installed).

Successfully searched home directory with mlocate

Below is the first 10 outputs after running locate home (locate is aliased to mlocate):

/home
/etc/apparmor.d/tunables/home
/etc/apparmor.d/tunables/home.d
/etc/apparmor.d/tunables/home.d/site.local
/etc/systemd/homed.conf
/home/username
/home/username/.bash_history
/home/username/.bash_profile
/home/username/.bashrc
/home/username/.cache
/home/username/.cargo

As you can see, I could successfully find files in my home directories with mlocate.

Unsuccessfully searched home directory with plocate:

However, after installing plocate, I get results from /etc/, /usr/ etc, and all I get is one /home:

After running locate home (locate is aliased to plocate):

/home
/etc/apparmor.d/tunables/home
/etc/apparmor.d/tunables/home.d
/etc/apparmor.d/tunables/home.d/site.local
/etc/systemd/homed.conf
/usr/bin/addgnupghome
/usr/bin/homectl

As you can see, plocate couldn't find files and directories in my home directory.

What I've tried

1. Comment from author of plocate

This manjaro thread How to use plocate? has the author of plocate commented as below:

First, check that the database has been updated recently. Most users will want to use plocate’s updatedb; plocate-build (which converts from mlocate’s database) is generally not what you want since plocate 1.1.0. [...]

The other reason why a file isn’t shown, is typically permissions. Check if you can find the files as root (sudo plocate test); if you can, the problem is most likely that you don’t have access rights to the directory all the way down from the root. plocate should find anything that find / -name test does, but no more.

I've run sudo updatedb.

My home dir access right:

/ 
➜ ll
drwxr-xr-x - root 17 Jul  2022 home/
drwxr-xr-x - root 16 Apr 21:44 usr/

/home 
➜ ll
drwxr-xr-x - username 16 Apr 21:51 username/

It does seem that plocate couldn't access files and directories under my home dir, but it has the same access right as usr. I don't understand why plocate can see usr but not files and dir under home.

2. Results are different when running as sudo

The results are different when I run plocate as sudo.

Below is regular locate:

➜  locate ranger
/usr/bin/ranger
/usr/lib/python3.10/site-packages/ranger
/usr/lib/python3.10/site-packages/ranger_fm-1.9.3-py3.10.egg-info
/usr/lib/python3.10/site-packages/ranger/__init__.py
/usr/lib/python3.10/site-packages/ranger/__pycache__

Below run as sudo:

➜  sudo locate ranger
/root/.config/ranger
/root/.local/share/ranger
/root/.local/share/ranger/bookmarks
/root/.local/share/ranger/history
/root/.local/share/ranger/tagged
/usr/bin/ranger
/usr/lib/python3.10/site-packages/ranger
/usr/lib/python3.10/site-packages/ranger_fm-1.9.3-py3.10.egg-info

I can see results in my home directories (i.e., first 5 results).

What I want

I'd like to be able to search my home directory with plocate the way I can do so with mlocate. In other words, I expect results from home directory when using plocate:

$ locate home
/home
/etc/apparmor.d/tunables/home
/etc/apparmor.d/tunables/home.d
/etc/apparmor.d/tunables/home.d/site.local
/etc/systemd/homed.conf
/home/username
/home/username/.bash_history
/home/username/.bash_profile
/home/username/.bashrc
/home/username/.cache
/home/username/.cargo
6
  • 1
    What do you get when you take fzf out of the loop? With it this is not a minimal reproducible example. Apr 16, 2023 at 17:34
  • Please see the updated session "2. Results are different when running as sudo".
    – kohane15
    Apr 17, 2023 at 0:51
  • That new section looks exactly as expected. root can only see files in their own directory. Non-root user cannot see into root's home. I'm still not understanding what you are asking. My original comment still stands; take out the fzf filtering and tell us what you expect to happen. Apr 17, 2023 at 23:33
  • @AaronD.Marasco Hello I've updated the question. I've taken out fzf and restructured the question. Thank you again for following up my question. I appreciate it.
    – kohane15
    Apr 18, 2023 at 15:32
  • Looking at the man page, it seems that you may have an alias or something setting the -b option because it is ignoring home when it's part of the path. Does 'which locate' say it's an alias or something? Apr 19, 2023 at 0:31

1 Answer 1

3

TL:DR: if you're using btrfs, do the following:

  1. edit /etc/updatedb.conf
  2. replace PRUNE_BIND_MOUNTS = "yes" with PRUNE_BIND_MOUNTS = "no"
  3. save the file
  4. update the db with sudo updatedb
  5. test again with locate home to see any outputs from home directory.

Explanation

I contacted plocate author and he kindly sent me to the right direction with the following reply:

90% of these issues seem to be btrfs misconfigurations. You don't say which filesystem you're running, but if so, see the updatedb.conf man page under PRUNE_BIND_MOUNTS and check your fstab.

I'm indeed using btrfs (to check: lsblk -f).

Consulting man updatedb.conf gives the following:

PRUNE_BIND_MOUNTS

One of the strings 0, no, 1 or yes. If PRUNE_BIND_MOUNTS is 1 or yes, bind mounts are not scanned by updatedb(8). All file systems mounted in the subtree of a bind mount are skipped as well, even if they are not bind mounts. As an exception, bind mounts of a directory on itself are not skipped. Note that Btrfs subvolume mounts are handled internally in the kernel as bind mounts (see btrfs-subvolume(8)), and thus, may get skipped if you have also mounted the filesystem root itself. To counteract this, make your root directory a Btrfs subvolume, too.

By default, bind mounts are not skipped.

For solution, please see the above TL;DR.

1
  • 3
    That's downright insane. Hopefully the plocate author will add that caveat to the docs. Apr 19, 2023 at 23:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .