# Repairing filesystems with fsck/e2fsck On April 12 a linux box experienced problems booting. The ultimate problem was that there were no filesystems listed in /etc/fstab. On the way to discovering this we had to do some diagnostics to ensure that the filesystems were not corrupt. To do this, we use fsck for ext3 filesystems and e2fsck for ext2 filesystems (of which we do not have any). Here are some steps that might be helpful when getting 'bad superblock' and filesystem errors on boot: #1) Get to a command-line environment: o Drop into a 'repair shell' if it gives you the option. o Boot from the Knoppix CD if no other options exist. #2) Check to see what filesystems are mounted: o Run # > df -h #3) Check the filesystem mappings: o Run # > fdisk o Here, may be /dev/hda, /dev/hdb, /dev/hdd, or some other filesystem. o Here is the output from running # > fdisk /dev/hdb on Pecos... ======================================================================================== [root@machine_name username]# fdisk /dev/hdb The number of cylinders for this disk is set to 30401. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p #this prints the fdisk journal Disk /dev/hdb: 250.0 GB, 250059350016 bytes 255 heads, 63 sectors/track, 30401 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hdb1 * 1 13 104391 83 Linux /dev/hdb2 14 1288 10241437+ 83 Linux /dev/hdb3 1289 1670 3068415 82 Linux swap /dev/hdb4 1671 30401 230781757+ f Win95 Ext'd (LBA) /dev/hdb5 1671 1925 2048256 83 Linux /dev/hdb6 1926 2052 1020096 83 Linux /dev/hdb7 2053 30401 227713311 83 Linux Command (m for help): q #this quits the fdisk environment ======================================================================================== #4) Check /etc/fstab to see what needs to be mounted: o Here is a copy of /etc/fstab file from Pecos... ======================================================================================== machine_name: ~>cat /etc/fstab /dev/hdb5 / ext3 defaults 1 1 /dev/hdb1 /boot ext3 defaults 1 2 none /dev/pts devpts gid=5,mode=620 0 0 /dev/hdb7 /home ext3 defaults 1 2 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0 /dev/hdb6 /tmp ext3 defaults 1 2 /dev/hdb2 /usr ext3 defaults 1 2 /dev/hdb3 swap swap defaults 0 0 /dev/hda2 /home2 ext3 defaults 1 2 /dev/hdd1 /home3 ext3 defaults 1 2 /dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0 /dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0 ======================================================================================== #5) Check filesystem integrity on partitions to be mounted: o Run # > fsck /dev/hdb### o Here, ### should be replaced by the map number (1,2,3,5,6,7) !Not on /hdb4! o Running #fsck# should tell you the name of the partition and if it is clean. #6) Repairing filesystems: o You can interactively repair filesystems using # > fsck -r o You could use a different superblock using # > e2fsck -b 8193 #7) Mount the clean filesystems: o Run # > mount /dev/hdb1 /boot o Run # > mount /dev/hdb2 /usr o Run # > mount ...and so on... o Check to see if they have been mounted by running # > df #8) If you are in a read-only environment, try this: o Run # > mount -o remount,rw # Other possibilities: o Try running 'debugfs', it is an ext2 filesystem debugger: ======================================================================================== DEBUGFS(8) DEBUGFS(8) NAME debugfs - ext2 file system debugger SYNOPSIS debugfs [ -b blocksize ] [ -s superblock ] [ -f cmd_file ] [ -R request ] [ -V ] [ [ -w ] [ -c ] [ -i ] [ device ] ] DESCRIPTION The debugfs program is an interactive file system debugger. It can be used to examine and change the state of an ext2 file system. device is the special file corresponding to the device containing the ext2 file system (e.g /dev/hdXX). ======================================================================================== o Try running 'dumpe2fs' for block information ======================================================================================== DUMPE2FS(8) DUMPE2FS(8) NAME dumpe2fs - dump filesystem information SYNOPSIS dumpe2fs [ -bfhixV ] [ -ob superblock ] [ -oB blocksize ] device DESCRIPTION dumpe2fs prints the super block and blocks group information for the filesystem present on device. dumpe2fs is similar to Berkeley’s dumpfs program for the BSD Fast File System. ========================================================================================