TransWikia.com

Sudo updatedb `/var/lib/mlocate/mlocate.db' is locked due to faulty drive, how to resolve permanently?

Unix & Linux Asked by Pro Backup on February 5, 2021

This 4.20.3 Arch system its BTRFS formatted / disk is without free space left. It turns out that mlocate is the cause:

# du -h --exclude=Volumes -- * 2>/dev/null | sort -hr | head -2
11G var
9.6G    var/lib/mlocate

The question updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db' accepted answer suggests to prepend sudo, though that doesn’t change a thing:

# sudo updatedb
updatedb: `/var/lib/mlocate/mlocate.db' is locked (probably by an earlier updatedb)

There seems to be a temporary file in /var/lib/mlocate that is eating up all disk space:

# ls -lh var/lib/mlocate/
-rw-r----- 1 root locate 1.1M Oct 21 00:00 mlocate.db
-rw------- 1 root root   9.6G Dec 30 19:46 mlocate.db.PRvfsw

Could the root cause be the .timer update job that is hanging?

# systemctl status updatedb.timer
* updatedb.timer - Daily locate database update
   Loaded: loaded (/usr/lib/systemd/system/updatedb.timer; static; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-21 16:05:10 CEST; 2 months 9 days ago
  Trigger: n/a

Both restart and stop don’t remove the temporary large .db file and updatedb still returns locked.

There seems to be an updatedb process still running:

# ps -ef | grep updatedb
root      3249     1 99 Oct22 ?        213573-14:47:11 /usr/bin/updatedb

I know I can kill this process. The root cause is most likely a faulty USB stick:

# ls /Volumes/RM_GUE__
ls: cannot access '/Volumes/RM_GUE__/'$'0120': Input/output error
ls: cannot access '/Volumes/RM_GUE__/)': Input/output error

Though the next time a USB stick becomes faulty, / will fill up again.

updatedb.conf

The updatedb.conf options don’t bring me any useful filter option:

  • by path: I can’t guess the name that the partition will have after corruption
  • by filesystem: In this case VFAT was corrupted (and read-only), though I can’t look in to the future which file system will get corrupted.

How to resolve this issue neat and permanently, for example by limiting the duration that updatedb.timer may run and/or skipping disks which suffer input/output errors, or limit the file size LimitFSIZE= or even something better?

One Answer

The documentation for mlocate (see man mlocate) leads to updatedb, which in turn says

The PRUNE_BIND_MOUNTS, PRUNEFS, PRUNENAMES and PRUNEPATHS variables, which are modified by some of the options, are documented in detail in updatedb.conf(5).

Reading the documentation for that (man updatedb.conf) and looking at the file /etc/updatedb.conf shows two possible options to satisfy your requirement:

PRUNEFS A whitespace-separated list of file system types (as used in /etc/mtab) which should not be scanned by updatedb(8). The file system type matching is case-insensitive.

PRUNEPATHS A whitespace-separated list of path names of directories which should not be scanned by updatedb(8). Each path name must be exactly in the form in which the directory would be reported by locate(1).

If your USB sticks and other removable media are always mounted under /Volumes you could add that directory to your PRUNEPATHS setting in /etc/updatedb.conf. On my Debian system this would result in

PRUNEPATHS="/tmp /var/spool /media /var/lib/os-prober /Volumes"

Alternatively, if your USB sticks are always FAT or NTFS you could add those filesystem types to the set of exclusions specified by PRUNEFS.

Answered by roaima on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP