Linux – Running out of memory running fsck on large filesystems

debianext3fscklinuxmemory

I look after an old Debian linux box (running etch) with only 512 MB of RAM, but a lot of external storage attached. One ext3 filesystem is 2.7 TB in size, and fsck can't check it, because it runs out of memory, with an error such as this one:

   Error allocating directory block array: Memory allocation failed
   e2fsck: aborted

I've added a 4 GB swap partition and it still doesn't complete, but this is a 32-bit kernel, so I don't expect adding any more will help.

Apart from booting into a 64-bit kernel, are there any other ways of getting fsck to complete its check?

Best Answer

A 64 bit kernel and large quantities of RAM will allow the fsck to finish nice and fast. Alternately, there's now an option in e2fsck that'll tell it to store all of it's intermediate results in a directory instead of in RAM, which helps immensely. Create /etc/e2fsck.conf with the following contents:

[scratch_files]
directory = /var/cache/e2fsck

(And, obviously, make sure that directory exists, and is on a partition with a good few GB of free space). e2fsck will run SLLOOOOWWWWWWW, but at least it'll complete.

Of course, this won't work with the root FS, but if you've got swap then you're past mounting the root FS anyway.