Search:  
Gentoo Wiki

Slocate_and_Rlocate

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc


Please format this article according to the guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article


This HOWTO will explain how to setup slocate and rlocate for a Gentoo system.

Contents

Background

Slocate is a tool to search the filesystem for a file with a given name. It's advantage over other such tools, namely "find", is its near-instantaneous results. This is achieved by maintaining a local database of file names in the file /var/lib/slocate/slocate.db. An accompanying program, updatedb, is used to update the database.

Rlocate bills itself as a "locate implementation that is always up-to-date". It is currently within beta release, requiring the 2.6 Linux kernel. It functions as a kernel module, maintaining a differential database of the files created and deleted since the last time updatedb was run. With rlocate, it checks both its differential database and the updatedb one (/var/lib/rlocate/rlocate.db, providing search results that are supposedly no more than 2 seconds old.

Slocate

Installation

To emerge slocate, just

emerge slocate

Then setup the initial database with

updatedb

It will probably warn that /var/lib/slocate/slocate.db does not exist, which is to be expected (we're creating it). This could take a while. To make sure it's all set up, just try a quick locate as such

locate home

which should spit out all the files with the word "home" in their name.

It should be noted that "locate" and "slocate" actually point to the same binary and are synonymous. The above search could have been accomplished with the below as well.

slocate home

Rlocate

Rlocate allows nearly-instanteous up-to-date searches. It is maintained at http://rlocate.sourceforge.net/.

Pre-install

Warning: Kernels 2.6.24 and newer do not support building LSM as a module, thus rlocate is broken and will not emerge. For more information see Gentoo Bug #20741


Rlocate requires a 2.6 Linux kernel. Additionally, it requires that "Enable different security models" is set to yes. "Default linux capabilities" must be either disabled or set to "M" in the kernel "Security options" section. Also disable NSA SELinux.

Note: The capability module cannot be loaded at the same time as rlocate.


Rlocate is an alternative to slocate, and both cannot be emerged at the same time. Slocate will block installing rlocate, so, if slocate is already installed, just

emerge -C slocate

Rlocate, being a beta program, is masked. So, first, unmask it with

echo "sys-apps/rlocate" >> /etc/portage/package.unmask

Installation

To install rlocate, simply

emerge rlocate

Setup the initial database with

updatedb

Now you can test that it works. Load the rlocate kernel module and start up the daemon by

/etc/init.d/rlocated start

Comment: This does "modprobe rlocate" too if necessary.

To test it, just create some new file and try to locate it

touch myself
locate myself

Note that "locate" and "rlocate" are synonymous with this package installed. The above command should show all the files one your system with "myself" in their path, including the one just created. As a sanity check, delete the file and search for it again with

rm -f myself
locate myself

Now it shouldn't show that file.

Post-install

If rlocate seems to be in working order, it is a good idea to set it up to be run on the next boot. This is accomplished by adding the daemon to the default runlevel with the below command.

rc-update add rlocated default

Additionally, you'll want to autoload the rlocate module on boot, so run the following command Comment: Is there any advantage when doing so ? Module will be loaded anyway when init-script is started.

echo "rlocate" >> /etc/modules.autoload.d/kernel-2.6

Issues and Notes

Permissions

If a non-root user has issues running locate, it most likely is due to improper permissions.

Run

ls -l /var/lib/

The directory slocate or rlocate here should belong to the "locate" group and provide read and execute access to this group. Also check

ls -l /var/lib/slocate/

or

ls -l /var/lib/rlocate/

It should provide read access to the group locate for the file slocate.db or rlocate.db and should not permit any access for others. There should be no execute access. Only root should need write access (assuming only root will be running updatedb).

If this is all set up and the user cannot run locate, he is most likely not a member of the group "locate". To check, simply

cat /etc/group | grep locate

The user should be listed. If not, just add him to the group:

usermod -aG locate username

or to allow all users (could be less save) check

ls -l /usr/bin/slocate

or

ls -l /usr/bin/rlocate

The file should belong to the group "locate", provide execute access to anybody and have SetGID set like so: "-rwxr-s--x 1 root locate ..." This can be achieved by:

chgrp locate /usr/bin/slocate ; chmod 2751 /usr/bin/slocate

or

chgrp locate /usr/bin/rlocate ; chmod 2751 /usr/bin/rlocate

Cron Job

Remembering to run updatedb can be a pain, so it is advisable to just make it a cron job. There should already be one in "/etc/cron.daily", if not run as root

crontab -e

Then add something along the lines of

0 1 * * *      updatedb

You can replace the "1" with whatever hour of the day you want it to run. Or, with vixie-cron, simply add

@daily         updatedb
Retrieved from "http://www.gentoo-wiki.info/Slocate_and_Rlocate"

Last modified: Sun, 18 May 2008 10:28:00 +0000 Hits: 3,150