Pages

Friday, July 20, 2012

Linux "locate" not working on /home

What is the "locate" command?

For years I have been using the locate command to find a file on my drive quickly. Unlike the command find, locate is SUPER fast because it reads from the database generated by updatedb which indexes of all the files on your drive!

Sonic boom!
(now Guile from Street Fighter II echos in your head)

I can't find my files under ~/

But locate suddenly becomes less useful when you can't find your own files! This might happen if you have your home drive encrypted! During a recent install of Ubuntu I was asked if I wanted to encrypt my home drive, I agreed.

If you look into updatedb's configuration, you will see a line starting with PRUNEFS which lists all the filesystem types that updatedb should exclude from the database. In the list, one of them is ecryptfs, which is the filesystem type of my encrypted home:
$ mount | grep ecryptfs
/home/aconrad/.Private on /home/aconrad type ecryptfs
So I had to edit the configuration file:
$ sudo vi /etc/updatedb.conf
and remove ecryptfs from the list. Finally run updatedb and now your files should be indexed and showing with locate.

I have been thinking about how this affects the safety of my files. If you think this is a bad practice, leave a comment explaining how enabling locate on an encrypted filesystem should be done.

3 comments:

  1. This helped me out. Thanks. This had me really boggled.

    ReplyDelete
  2. To hide your encrypted file list, do the following:

    updatedb -l 0 -o $HOME/mlocate.db -U $HOME

    then add this to your $HOME/.bashrc
    export LOCATE_PATH="$HOME/mlocate.db"

    then when you run locate it uses the default database first, then the one specified in your LOCATE_PATH (i.e. your home area). The one in your home area is encrypted though, keeping your file list safe.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete