e2fsck: Error allocating directory block array: Memory allocation failed

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, August 04, 2012

Follow me on Twitter as @mattiasgeniar

When you try to filecheck a large partition on a system with insufficient RAM, you can encounter the following error.

$ e2fsck -p -f /dev/vg_mnt/lv_mnt01
/dev/vg_mnt/lv_mnt01: Error allocating icount structure: Memory allocation failed
/dev/vg_mnt/lv_mnt01: Error allocating directory block array: Memory allocation failed
e2fsck: aborted

This happens because the e2fsck tries to store all inode information in memory, which may exceed the available memory size on the system.

To fix this, either upgrade the system with more memory or try to set additional options that allow e2fsck to create a temporary directory on a system with sufficient (several GB’s) free disk space. Not that this only works for e2fsck version 1.40 or higher (meaning: CentOS and RHEL users are screwed since they only provide 1.39).

$ rpm -qa | grep e2fsprogs
e2fsprogs-libs-1.39-34.el5_8.1
e2fsprogs-devel-1.39-34.el5_8.1
e2fsprogs-1.39-34.el5_8.1

To run the e2fsck with a recent version, try the following.

$ cd /usr/local/src
$ wget "http://kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.42.5/e2fsprogs-1.42.5.tar.gz"
$ tar xzf e2fsprogs-1.42.5.tar.gz
$ rm -f e2fsprogs-1.42.5.tar.gz
$ cd e2fsprogs-1.42.5
$ yum install gcc make
$ ./configure
$ make

The above will download e2fsck (the latest version as of this writing), compile and make it but leave it in the directory of the build (/usr/local/src/e2fsck), it won’t copy the binaries to your system. That means you can use the newly compiled binary at /usr/local/src/e2fsprogs-1.42.5/e2fsck/e2fsckw.

Now, since you have a e2fsck version higher than 1.40, you can set the options to use a scratch-disk and avoice the Out-of-Memory errors. First, create the directory.

$ mkdir -p /var/cache/e2fsck

And create a custom file called /etc/e2fsck.conf that contains the following content.

$ cat /etc/e2fsck.conf 
[scratch_files]
directory = /var/cache/e2fsck

This tells e2fsck to use a directory on disk if the total available memory is insufficient to host all inode information of the partition.

If you had to make a new e2fsck yourself because the OS didn’t have a recent version, start the new e2fsck as such.

$ /usr/local/src/e2fsprogs-1.42.5/e2fsck/e2fsck -f /dev/vg_mnt/lv_mnt01

If you had a recent version already, you can simply restart e2fsck with the system binary.

$ e2fsck -f /dev/vg_mnt/lv_mnt01

When the new e2fsck is running, you should see additional information appear in the cache-directory.

$ ls /var/cache/e2fsck/
total 475M
-rw-------  1 root root 106M Aug  5 13:16 2fb8a70e-8ee3-4c9c-b95b-0e42ae1ecebd-dirinfo-jthsIm
-rw-------  1 root root 368M Aug  5 13:16 2fb8a70e-8ee3-4c9c-b95b-0e42ae1ecebd-icount-ZxFa0u

If the directory is empty, your e2fsck is not using the scratch_files options set in /etc/e2fsck.conf and would probably indicate that it is running an older version that does not yet support this. See the compile commands above to compile the latest version yourself.

Happy fscking!



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.