Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
share|improve this question
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

2 Answers 2

up vote 12 down vote accepted

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:

  • Remove /media from PRUNEPATHS.
  • Mount the external drive unter /mnt.
  • Create a dedicated database for your external harddisk and query that on demand.

I do not recommend removing /media from PRUNEPATHS. 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.

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.

I will now explain how to 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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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