Make `locate` able to search files on external HDD

The locate database is generally configured to omit files on removable disks, since they can't be assumed to be there later. It can be configured through a file such as /etc/updatedb.conf (the location depends on which of the several locate programs you use and how it is configured by your distribution).

For a removable disk, it is probably better to keep the database in a separate file. Run

updatedb --localpaths=/media/my_removable_disk --output=/var/cache/locate/my_removable_disk.locatedb 

to update the database. Add /var/cache/locate/my_removable_disk.locatedb to the environment variable LOCATE_PATH; for reasonably recent versions of GNU locate, an empty path component stands for the default path, so you can use

export LOCATE_PATH=:/var/cache/locate/my_removable_disk.locatedb

If you want to keep the locate database on the removable disk, don't add the path to LOCATE_PATH, because locate stops looking if one of the database files is missing. A wrapper script would be better:

locates () {
  locate "$@"
  for d in /media/*; do
    locate -d "$d/.locatedb" "$@"
  done
}

The config file is here: /etc/updatedb.conf, so if you didn't add anything, just mount your HDD, and do updatedb, then you would be able to search for files on external HDD partitions.