unknown partition table

Chris F.A. Johnson cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org
Sat Jul 1 04:34:18 UTC 2006


On Fri, 30 Jun 2006, Kevin Cozens wrote:

> Daniel Armstrong wrote:
>>  Does starting with a zero table mean I lose all data on the disk? How
>>  would I recover the previous partition table? Thanks for any help!
>
> It usually means you have lost all the data on the disk unless you know 
> *exactly* what the partition table settings were before. If you know the old 
> settings, you might be able to reset the table and regain access to your 
> data.

    I once lost my partition table, and wrote this script to recover
    it. You need to know the last sector on the drive, and it helps to
    know approximately where the last partition started.

lastsector=2498
n=400
while [ $n -lt 600 ]
do
    fdisk /dev/hda > /dev/null 2>&1 << EOT
    d       = delete
    1       = hda1
    n       = new one add
    p       = primary type
    1       = hda1
    $n      = next try @ start sector
    $lastsector    = last sector of disk
    p       = print partn-table
    w       = write partn-table to disk
EOT

    mount -t ext2 /dev/hda1 /d1 && exit || echo -e "\aMount failed $n"
    (( ++n ))
done

     I set that running, went away and had supper, and when I came back
     it had restored the last partition (which was the largest, and the
     only one I really cared about). This could be modified to reset
     lastsector to the one preceding the successful beginning section
     and try from there, eventually rebuilding the whole table.

-- 
    Chris F.A. Johnson                      <http://cfaj.freeshell.org>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list