Recover my lost partition table

My friend told me last morning that, a Trixbox CD ISO, which I helped to add a HTML with some graphics files, couldn’t be identified itself as a Centos CD by its installer.

I tested the CD booting again after I added a missing file. But unfortunally it is failure to load my GRUB on reboot after the testing. I felt it was possible that my partition table was lost. Oh my god!

I booted it with Ubuntu LiveCD to try to recover my partition table. I found a useful software called gpart from mini-HOWTO with a help of google, and downloaded it from Ubuntu universe responsity.

Edit /etc/apt/sources.list file and add the “universe” at the following line.
deb http://tw.archive.ubuntu.com/ubuntu/ edgy main restricted universe

Then, I get the gpart package with apt-get after updating of package index file from sources, and next, I execute gpart to check my hda.

$ apt-get update
$ apt-get install gpart
$ gpart /dev/hda
Begin scan…
Possible partition(DOS FAT), size(19994mb), offset(0mb)
Possible partition(DOS FAT), size(19994mb), offset(19994mb)
Possible partition(Linux ext2), size(9993mb), offset(59984mb)
Possible partition(Linux swap), size(486mb), offset(69978mb)
Possible partition(Linux ext2), size(8063mb), offset(70464mb)

* Warning: short read near sector(160836291), 64512 bytes instead of 66048. Skipping…
End scan.

Checking partitions…

* Warning: more than 4 primary partitions: 5.
Partition(DOS or Windows 95 with 32 bit FAT): primary
Partition(DOS or Windows 95 with 32 bit FAT): primary
Partition(Linux ext2 filesystem): primary
Partition(Linux swap or Solaris/x86): primary
Partition(Linux ext2 filesystem): invalid primary
Ok.

Guessed primary partition table:
Primary partition(1)
type: 011(0x0B)(DOS or Windows 95 with 32 bit FAT)
size: 19994mb #s(40949622) s(63-40949684)
chs: (0/1/1)-(1023/15/63)d (0/1/1)-(40624/10/63)r

Primary partition(2)
type: 011(0x0B)(DOS or Windows 95 with 32 bit FAT)
size: 19994mb #s(40949622) s(40949748-81899369)
chs: (1023/15/63)-(1023/15/63)d (40624/12/1)-(81249/5/63)r

Primary partition(3)
type: 131(0x83)(Linux ext2 filesystem)
size: 9993mb #s(20466744) s(122849118-143315861)
chs: (1023/15/63)-(1023/15/63)d (121874/2/1)-(142178/6/60)r

Primary partition(4)
type: 130(0x82)(Linux swap or Solaris/x86)
size: 486mb #s(995960) s(143315928-144311887)
chs: (1023/15/63)-(1023/15/63)d (142178/8/1)-(143166/8/56)r

gpart searched the hard disk and guess the possible range of each partitions as the above. In my memories, I got few logical partitions created in a extended partition, and partitions were not identified in correct order.

From the above gpart result, I still could not find out my /home partition, damn. I started to guess and calculate the possible range in sector no. of my /home.

My calculator and paper working

I found that a gap occurs between each partitions. My 1st Windows partition is ended at CHS 40624/10/63, but my 2nd Windows partition is started from 40624/12/1. Therefore I guessed the possible range of my /home is from 81249/7/1 to 121873/16/63, which should be from sector 81899433 to 122849053 according to my calculation.

To start a risky re-creation of my partition table with fdisk, I found I can create partition in term of sector range after I pressed ‘u’ to change the display/entry units to sectors. And I mounted these partitions successfully after the re-creation.

$ fdisk /dev/hda -l -u
Disk /dev/hda: 82.3 GB, 82348277760 bytes
16 heads, 63 sectors/track, 159560 cylinders, total 160836480 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/hda1 63 40949684 20474811 b W95 FAT32
/dev/hda2 40949748 81899369 20474811 b W95 FAT32
/dev/hda3 81899433 122849053 20474810+ 83 Linux
/dev/hda4 122849054 160836479 18993713 5 Extended
/dev/hda5 122849118 143315861 10233372 83 Linux
/dev/hda6 143315928 144311887 497980 82 Linux swap / Solaris

But my GRUB still couldn’t be loaded because related files couldn’t be found. I tried to mount the / partition after boot-up of Ubuntu LiveCD, and then I re-create the full partition table again according to /etc/fstab, to use the original partition id.

Oh… GRUB is successfully be loaded. No re-installation of OS was required, and my files are found.

I heard that partition table of my friend’s PC is also deleted by original trixbox CD. I told him that we didn’t read a warning at the boot prompt screen of Trixbox. So careless we are. And we think that a warning message should be printed on the CD I produced.
Thanks to open sources!

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

*