Oopsie.
If your main goal is to keep the system up and running in a tolerable state rather than immediate eradication of all errors, here's my approach for your reference. I have a single ext3 filesystem on /dev/ubda running Debian GNU/Linux, so you might need to change the commands around a bit to adapt to your filesystem / device / distro.
When a running (but not very busy) Linux system dies catastrophically, the files most likely to be corrupted are:
- opened log files;
- perpetually active directories like /var/spool/* and /tmp;
- random inodes that are in the vicinity of inodes pointing to (1) and (2) above. I don't know why; that's just the way it is.
(1) and (2) are probably already fixed while your system rebooted. If they aren't, you can likely fix them by deleting and re-creating the offending files/directories, so they're no biggie.
As for (3), you'll need to rely on e2fsck (or whatever is the fsck your filesystem uses -- pardon the pun) to find them. Here's what I did.
(Execute all the following over and over until no directory-level errors are reported.)
Code:
# e2fsck -n /dev/ubda > errs
e2fsck 1.35-WIP (07-Dec-2003)
e2fsck: aborted
(The -n flag makes e2fsck perform a dry run without making changes. All the errors that e2fsck reports are now in the file "errs".)
Code:
# cat errs
[ ... Lots of lines omitted ...]
Pass 2: Checking directory structure
Directory inode 231197, block 0, offset 0: directory corrupted
Salvage? no
(Just pay attention to the last few lines; this is where directory-level errors are detected. In this example, e2fsck says inode 231197 is dead. So go and look for it.)
Code:
# find / -inum 231197
/usr/X11R6/lib/X11/locale/koi8-u
(Let's see how screwed up this directory is.)
Code:
# ls -alF /usr/X11R6/lib/X11/locale/koi8-u
total 0
(Hmm... completely screwed up. Nonetheless it looks like this isn't a crucial directory, so we can just scrap it and re-create it. First, find out which package provides this directory. Then force a re-install of that package. -- Note: These are Debian-specific commands. Vary according to distro.)
Code:
# dpkg -S /usr/X11R6/lib/X11/locale/koi8-u
xlibs: /usr/X11R6/lib/X11/locale/koi8-u
# \rm -rf /usr/X11R6/lib/X11/locale/koi8-u
# apt-get --reinstall install xlibs
Reading Package Lists... Done
Building Dependency Tree... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 1377kB of archives.
After unpacking 0B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ftp.us.debian.org unstable/main xlibs 4.2.1-14 [1377kB]
Fetched 1377kB in 1s (1026kB/s)
(Reading database ... 21836 files and directories currently installed.)
Preparing to replace xlibs 4.2.1-14 (using .../xlibs_4.2.1-14_i386.deb) ...
Unpacking replacement xlibs ...
Setting up xlibs (4.2.1-14) ...
(Now we should be all set.)
Code:
# ls -alF /usr/X11R6/lib/X11/locale/koi8-u
total 6
drwxr-xr-x 2 root root 1024 Dec 25 00:22 ./
drwxr-xr-x 49 root root 2048 Dec 25 00:22 ../
-rw-r--r-- 1 root root 376 Nov 14 06:37 Compose
-rw-r--r-- 1 root root 338 Nov 14 06:37 XI18N_OBJS
-rw-r--r-- 1 root root 979 Nov 14 06:37 XLC_LOCALE
(Voila. One directory fixed. Repeat until e2fsck no longer reports
directory-level errors.)
Provided that all the corrupted directories are managed by your distro without your own customization, you can at least fix all directory-level errors that may cause programs to die whenever they access these directories.
This process does not fix everything. You'll likely end up with a bunch of orphaned inodes (directories you deleted and files therein), unattached inodes, and incorrect inode counts. But at least they're no longer showstoppers.
This process only buys you time to worry about a complete fix later. It's probably unsafe to ignore the remaining errors forever, and I do intend to bring down the filesystem and run a real e2fsck (without the -n flag) at some point. (Only not during Christmas.)
Hope this helps somehow.
