Wednesday, 4 November 2009

Howto: Adjust updatedb.mlocat to a sensible time.

All credit for this goes to This Blog Entry where I found this helpful information.

If you are an early riser like myself (well, occasionally at least) then you may notice your PC grinding away on its harddrives like a mad thing. I have around 3TB of storage so the problem is exacerbated somewhat. The process to blame is updatedb.mlocat which runs between 6am and 7am, I want a quiet morning with my coffee so I am going to show you how to move it to between 3am and 4am

The job parameters are listed in /etc/cron.daily/mlocate. We don't edit anything here, its just for reference.

#! /bin/sh

set -e

[ -x /usr/bin/updatedb.mlocate ] || exit 0

# See ionice(1)
if [ -x /usr/bin/ionice ]; then
IONICE=”/usr/bin/ionice -c3″

$IONICE /usr/bin/updatedb.m

The files in /etc/cron.daily are kicked off by /etc/crontab, not by root’s crontab. For some reason, Ubuntu’s default install runs this process around 6am. Changing this file allowed me to make the job run at 3am. Here we change the hour time to 3 instead of 6, so you will need a sudo gedit or something to adjust this... carefully.. sudo gedit /etc/crontab

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don’t have to run the `crontab’
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.


# m h dom mon dow user command
17 * * * * root cd / && run-parts –report /etc/cron.hourly
25 3 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.daily )
47 3 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.weekly )
52 3 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.monthly )

updatedb can be configured to ignore certain paths - since my machine has a number of drives used for backups, I wanted to exclude those from the updatedb job. I accomplished this by editing /etc/updatedb.conf and adding to the PRUNEPATHS listing. Adding paths to the PRUNEPATHS option instructs updatedb to exclude those paths from indexing.

PRUNEPATHS=”/tmp /var/spool /media /mnt/backup”
PRUNEFS=”NFS nfs nfs4 afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf rpc_pipefs”