20

Files from my external hard drive are no longer indexed after rebooting. I have to remount and then run

# updatedb

after each reboot. The problem is updatedb takes a few minutes for my external hard drives. Is there any way I can retain indexing for my externals after I reboot so that the locate command can search through my externals?

EDIT: Per Request here are my specs:

$ cat /etc/updatedb.conf
PRUNE_BIND_MOUNTS="yes"
# PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media"
PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs"

# mount
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon on /home/me/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=me)
/dev/sdb1 on /media/me type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096,default_permissions)
/dev/sdd1 on /media/Little Boy type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096,default_permissions)
/dev/sde1 on /media/Fat Man type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096,default_permissions)

# on_ac_power; echo $?
255
  • 1
    Please provide the config files and mount options: cat /etc/updatedb.conf, mount, on_ac_power; echo $? – arrange Sep 6 '11 at 10:29
  • will do, won't have access to a linux machine for about 8 more hours – user784637 Sep 6 '11 at 17:53
  • Arrange, I've updated my answer with my specs, thanks for your help =) – user784637 Sep 7 '11 at 3:40
  • <note for the future>Here's how to GENERALLY figure out what updatedb is doing: (1.) Run updatedb with --verbose and --debug-pruning. (2.) Look at the text to see what is being indexed and not being indexed --> adjust your /etc/updatedb.conf. I grepd for files that I needed but were being skipped. For example I had modify /etc/updatedb.conf with: (1.) PRUNE_BIND_MOUNTS = "no" (2.) remove nfs nfs4 nfsd autofs from PRUNEFS (3.) remove /net from PRUNEPATHS – Trevor Boyd Smith Jun 6 '17 at 13:37
35

Files from your external harddisk are not indexed because updatedb is configured to not index anything under /media, which is where external storage is usually mounted. This configuration is set in the file /etc/updatedb.conf. Specifically the entry /media in the PRUNEPATHS line.

Some ideas how you can make updatedb to index your external drive:

1. Mount the external drive unter /mnt.

If your external harddisk is supposed to be mounted permanently then I suggest to configure it so that it is mounted under /mnt instead of under /media. That can usually be done by editing /etc/fstab. Search for "fstab" to learn about that. You will need sudo rights to edit /etc/fstab.

2. Create a dedicated database for your external harddisk and query that on demand.

The following command will create a dedicated database:

updatedb -l 0 -o ~/.externalharddisk.db -U /media/externalharddisk

This will create the database in the hidden file .externalharddisk.db in your home. You do not need sudo for that command. Execute the same command again to keep the database updated. Carefull: if you run that command while the external harddisk is not mounted then updatedb will think the files are deleted and will empty the database.

You can set up a script to automate that task. Search for "cronjob" to learn how to do that. Note: you can set up a user cronjob as user. You do not need sudo rights to set up a user cronjob.

The following command will query the database:

locate -d ~/.externalharddisk.db searchterm

You can also query the dedicated database and the default database at the same time:

locate -d ~/.externalharddisk.db: searchterm

The colon at the end followed by nothing means to also search in the default database.

You can make an alias for easier use. Put the following line in your .bashrc:

alias locate-external='locate -d ~/.externalharddisk.db:'

Now you can use locate to search only the default database and locate-external to also search in your external harddisk.

3. Remove /media from PRUNEPATHS

Note: I do not recommend this! This is because of the way updatedb works. If updatedb runs while the external harddisk is removed then all entries pointing to the external harddisk will be removed from the database. If updatedb runs while the external harddisk is connected then entries pointing to the external harddisk will be added again. Since updatedb is running regulary in the background you can never be sure whether the files from the external harddisk are currently indexed or not.

Furthermore: if you remove /media from PRUNEPATHS, this behaviour will also apply to any other external storage you happen to have mounted while updatedb is updating the database.

  • 2
    You can additionally add this alias to your ~/.bashrc file: alias updatedb-external='sudo updatedb -l 0 -o ~/.externalharddisk.db -U /media/externalharddisk' – rubo77 Sep 3 '15 at 5:30
  • +1 to both you and OP. However rather than a separate external DB command ie locate-external, I'm considering appending three databases into one with --database /mnt/c... for WSL, --dataabase /mnt/e... for WSL+Linux shared scripts & documents and --database /var/lib/mlocate/mlocate.db for dual-booted Ubuntu 16.04. ie All three databases on the same locate command line (with an alias of course). But before I start it would be nice to know if it will work. Can I get your thoughts on that? – WinEunuuchs2Unix Nov 11 '17 at 19:15
  • I don't agree with the argument of removing /media from PRUNEPATHS. While yes it has the problem you mentioned, excluding it entirely is even worse - you will NEVER locate files on those drives. It's like amputating your fingers so they don't get burnt while cooking (unless there's another obvious solution that is implied which I'm not seeing). – Sridhar Sarnobat May 29 at 0:44
2

In updatedb.conf you have /media in PRUNEPATHS. You should remove it, since your external drives seem to be mounted there.

2

These are further embellishments to be added to Lesmana's answer

[1] slight embellishment: may i suggest adding the -i to make sure case of the query searched is no longer an issue: so to add to .bashrc >>

alias locate-external='locate -d ~/.externalharddisk.db: -i'

[2] As regards the updating of both databases; the one in the main HD and the new one in the external; it is probably worth adding one more entry to the .bashrc

alias updateALL='sudo updatedb && updatedb -l 0 -o ~/.externalharddisk.db -U /media/externalharddisk'

and then to simply run updateALL in terminal to update both databases at once

PS:of course do not forget to run . ~/.bashrc to firm it all up once a new line is saved in the .bashrc
PS²: and of course too externalharddisk in all the lines above is replaced by the name of your external HD name ie /media/YOURHDNAME

*PS³ and you can of course conflate both update and locate in your .bashrc

alias LO='sudo updatedb && updatedb -l 0 -o ~/.externalharddisk.db -U /media/externalharddisk ; locate -d ~/.externalharddisk.db: -i'

so now all you need to update and search is to enter LO 'followed by the terms you seek'

  • +1 for sequencing update and then locate – LMSingh Feb 8 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.