Ext 2 Superblock Finder Carlo Contavalli Thu Jan 3 16:54:17 CET 2002 This file documents e2sbf, a small bash script I wrote to help me out rescuing damaged ext2 partitions. This manual, the mentioned script and all the provided files are copyright © Carlo Contavalli 2000-2002. Please read the following sections for more details. Note that this is free software and authors hold no responsability for any damage or loss, direct or indirect, caused by using this software. Use it only on your OWN risk and AFTER carefully reading this documentation. The latest version of this document can be found at . ______________________________________________________________________ Table of Contents 1. License, copyright and... 2. About this script... 3. Installation 4. Usage ______________________________________________________________________ 1. License, copyright and... This document and e2sbf were written by Carlo Contavalli and are thus Copyright © Carlo Contavalli 2001-2002. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Any example of program code available in this document should be considered protected by the terms of the GNU General Public License. e2sbf is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. e2sbf is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Trademarks are owned by their respective owners. 2. About this script... e2sbf is a small script to help rescuing damaged ext2 partitions. It has been written in an afternoon to help me recover a friend's partition. It works by asking mke2fs where it would put backup copies of the superblock on the given partition, and then trying if those sectors contain a valid superblock using e2fsck (an effort was made to use mount -o sb=... but I couldn't make it work as wanted). If no superblock is found, it then tries all the sectors starting from the closest to those indicated by mke2fs. The script terminates when: · A valid superblock is found or · All sectors have been checked WARNING!! This script relies on the -n parameter of mke2fs and on the same parameter of e2fsck. It is not possible for the script to test whenever such parameter is accepted or if it has the intended meaning! Please go on reading this document before using this e2sbf! You can find the latest version of this document and the mentioned software at http://www.commedia.it/ccontavalli/. If you have troubles/suggestions/corrections feel free to mail me at . 3. Installation 1. unpack the tarball with: $ tar -xvzf ~/e2sbf.tar.gz 2. Check that the following tools are installed on your system: · A recent bash version (any 2.x.x should be good -- must support arrays and arithmetic operations) · e2fsck (tested with 1.19) · mke2fs (tested with 1.19) · cut, tail, grep, head, sed, true and other standard unix utilities. 3. Check on the manual and with --help that both e2fsck and mke2fs accept the -n parameter and that it means ``don't do what you are told to, just display what you would do''. WARNING!! If you are not sure that -n is accepted by your e2fs tools and that it has the intended meaning don't use the provided script! Do not even try to run ``mke2fs -n'' on any partition just to see if ``-n'' is accepted. YOU MAY DAMAGE ALL YOUR DATA!! Read the manual, and if still unsure, do not use this script! 4. A good idea would be to make a backup copy of the partition you have damaged on the hard drive and then run e2sbf on that file with something like: # cat /dev/hda1 > /tmp/hda1.backup # e2sbf /tmp/hda1.backup 4. Usage After you are sure your system is ready to use this script (read the installation section, otherwise you may DAMAGE your data!), run something like: # e2sbf /dev/hda1 as superuser, where /dev/hda1 is your partition or a backup copy of it. The script should print a list of preliminary checks (to make sure that all needed tools are installed and that the bash is of the right version) and then a list of sectors the script is testing. In case a superblock is found, a line of ``*'' followed by ``Found: number'' is written on the screen, where number is the sector where the superblock was found, suitable for usage with the ``-b'' parameter of e2fsck. It is possible to specify a ``logfile'' as a second parameters in order to log the output of all the commands run. Here is an example output: Looking for mke2fs: /sbin/mke2fs Looking for e2fsck: /sbin/e2fsck Looking for grep: /bin/grep Looking for head: /usr/bin/head Looking for tail: /usr/bin/tail Looking for cut: /bin/cut Looking for sed: /bin/sed Looking for true: /bin/true Testing bash abilities (any error here means that no support is present)... Testing for arithmetic support...OK. Testing for arrays support...OK. Estimated positions: 32768 98304 163840 Testing: 1 Testing: 2 Testing: 32768 ********************** Found: 32768 Some parameters are tunable on the first couple lines of the source of e2sbf. For example, with ``silent=on'' you can make e2sbf to be more silent while with ``stop_on_first_match=false'' you can tell e2sbf to scan the whole partition for all valid superblocks (in which case, you would probably use | grep 'Found:' |less). When this latest parameter is ``true'', e2sbf returns a status of 0 if a valid superblock is found, while a different number is returned for each different error (look at the script if you need the complete list of error codes). Watch out that the script will really slow down when a superblock is found, since it will wait for e2fsck to terminate (it is really slow, especially if the file system is damaged). If ``-n'' is correctly accepted by your e2fs tools, e2sbf will not modify your file system nor write on it in any case (finding a good superblock is a read-only test).