Skip to main content

Adding a shared drive to the locate database

·331 words·2 mins

I have a big drive on a fileserver that I store most things on. It’s big enough that it’s hard to search it manually, which is something I do often enough that I don’t really want to do that anymore. So I decided to add it to the locate database (updatedb).

Enable indexing
#

First, you have to tell locate that it’s allowed to search mounted filesystems. In my case, it’s an NFS mount; if you’re using CIFS you’ll need to do something slightly different.

  1. Figure out your file system types. Run:
sudo updatedb --debug-pruning

This gives you information about which filesystems you need to worry about when you’re deciding which to prune.

  1. Edit /etc/updatedb.conf

  2. In the PRUNEFS line, remove autofs, NFS, nfs, and nfs4.

  3. I noticed PRUNENAMES was commented out. It seemed like a good idea to uncomment that.

  4. While you’re in there, it’s probably smart to make sure the filesystem you want to index isn’t in PRUNEPATHS. Because I didn’t want to index all my mounts, just one, I added my other mounts to PRUNEPATHS. I ended up with:

/etc/updatedb.conf
PRUNE_BIND_MOUNTS="yes"
PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media /var/lib/os-prober /var/lib/ceph /home/.ecryptfs /var/lib/schroot /cifs_share /other_nfs_share"
# PRUNEFS="NFS afs autofs binfmt_misc ceph cgroup cgroup2 cifs coda configfs curlftpfs debugfs devfs devpts devtmpfs ecryptfs ftpfs fuse.ceph fuse.cryfs fuse.encfs fuse.glusterfs fuse.gocryptfs fuse.gvfsd-fuse fuse.mfs fuse.rclone fuse.rozofs fuse.sshfs fusectl fusesmb hugetlbfs iso9660 lustre lustre_lite mfs mqueue ncpfs nfs nfs4 ocfs ocfs2 proc pstore rpc_pipefs securityfs shfs smbfs sysfs tmpfs tracefs udev udf usbfs"
# removed NFS, autofs, nfs, and nfs4
PRUNEFS="afs binfmt_misc ceph cgroup cgroup2 cifs coda configfs curlftpfs debugfs devfs devpts devtmpfs ecryptfs ftpfs fuse.ceph fuse.cryfs fuse.encfs fuse.glusterfs fuse.gocryptfs fuse.gvfsd-fuse fuse.mfs fuse.rclone fuse.rozofs fuse.sshfs fusectl fusesmb hugetlbfs iso9660 lustre lustre_lite mfs mqueue ncpfs ocfs ocfs2 proc pstore rpc_pipefs securityfs shfs smbfs sysfs tmpfs tracefs udev udf usbfs"
  1. Test again with:
sudo updatedb --debug-pruning
  1. Update the database.
sudo updatedb

This takes a while.

Using locate
#

This is just:

locate file_i_am_looking_for

or:

locate -i file_i_am_looking_for_When_I_dont_know_the_Case