Revision History | ||
---|---|---|
Revision v3.4 | 2002-08-22 | Revised by: jdd |
Minor update related only with docbook | ||
Revision v3.3 | 2001-11-17 | Revised by: jdd |
Minor update - docbook & revision history - emacs use. | ||
Revision v3.2 | 2001-09-25 | Revised by: jdd |
Major update. |
This mini-HOWTO addresses only the “lost partition table” problem. This can be when�:
A hard disk is made of sectors numbered from 0 to the max.
hdb: ST34321A, 4103MB w/128kB Cache, CHS=523/255/63 |
Let's get a look at (part of) my own print of fdisk -l�:
Disk /dev/hdb: 255 heads, 63 sectors, 523 cylinders Units = cylinders of 16065 * 512 bytes Device Boot Start End Blocks Id System /dev/hdb1 1 153 1228941 83 Linux /dev/hdb2 154 166 104422+ 82 Linux swap /dev/hdb3 * 167 291 1004062+ 83 Linux /dev/hdb4 295 523 1839442+ 5 Extended /dev/hdb5 295 422 1028128+ 83 Linux /dev/hdb6 423 523 811251 6 FAT16 |
This is my second hard disk, tied to guesses and tries (the first is too simple to be interesting).
/dev/hdb is my second ide disk (slave on the primary interface),
/dev/hdb1 is the first primary partition, running from the first (1) block to the block 153.
Here the fdisk -u -l listing of an other disk:
Disque /dev/hda : 240 t�tes, 63 secteurs, 2584 cylindres Unit�s = secteurs sur 1 * 512 octets P�riph�rique Amorce D�but Fin Blocs Id Syst�me /dev/hda1 * 63 10357199 5178568+ c Win95 FAT32 (LBA) /dev/hda2 15452640 39070079 11808720 83 Linux /dev/hda3 10357200 15150239 2396520 f Win95 Etdue (LBA) /dev/hda4 15150240 15452639 151200 84 Lecteur C: cach� OS/2 /dev/hda5 10357263 10463039 52888+ 83 Linux /dev/hda6 10463103 10780559 158728+ 82 Echange Linux /dev/hda7 10780623 15150239 2184808+ 6 FAT16 Les entr�es de la table de partitions ne suivent pas l'ordre du disque. |
All is simple if you have at hand�:
use fdisk to delete (d option) all the existing partitions on the damaged disk�;
use fdisk to create all the primary (1-4) partition mentioned on the paper�;
On my SuSE installation and anytime I had to do this for other peoples, this gives a good result.
hdparm -g /dev/hda1/dev/hda1: geometry���� = 2432/255/63, sectors = 4192902, start = 63
e2fsck -n /dev/hd?? |
You can even mount the partition and check the size:
mount -r /dev/hd?? /mnt df -T |
But there is a better way if you can still access the net or have “gpart” at hand. gpart is available in most distribution, by freshmeat.net or directly at http://www.stud.uni-hannover.de/user/76201/gpart.
“gpart - guess PC-type hard disk partitions” is the first line of the man page of gpart (man gpart).
“gpart tries to guess which partitions are on a hard disk. If the primary partition table has been lost, overwritten or destroyed the partitions still exist on the disk but the operating system cannot access them.” This is exactly what we need.
gpart is a very good tool.
The problem is the following: the first block of any partition is marked. But it's never “unmarked” if not overwritten. So many “first partition block” are existing on an old disk and gpart tries to do it's best guessing what is the good one. In fact it's not too difficult to try, nothing is written on the disk by gpart.
Here is the result of gpart on the previously seen disk hdb:
root@charles:/home/jdd > gpart /dev/hdb Begin scan... Possible partition(Linux ext2), size(1200Mb), offset(0Mb) Possible partition(Windows NTFS), size(1200Mb), offset(1200Mb) Possible partition(Linux ext2), size(1004Mb), offset(2402Mb) Possible partition(Windows NTFS), size(1600Mb), offset(4102Mb) End scan. Checking partitions... * Warning: partition(OS/2 HPFS, NTFS, QNX or Advanced UNIX) ends beyond disk end . Partition(Linux ext2 filesystem): primary Partition(OS/2 HPFS, NTFS, QNX or Advanced UNIX): primary Partition(Linux ext2 filesystem): primary Partition(OS/2 HPFS, NTFS, QNX or Advanced UNIX): invalid primary Ok. Guessed primary partition table: Primary partition(1) type: 131(0x83)(Linux ext2 filesystem) size: 1200mb #s(2457880) s(63-2457942) chs: (0/1/1)-(152/254/61)d (0/1/1)-(152/254/61)r Primary partition(2) type: 007(0x07)(OS/2 HPFS, NTFS, QNX or Advanced UNIX) size: 1200mb #s(2457880) s(2457944-4915823) chs: (152/254/63)-(305/253/60)d (152/254/63)-(305/253/60)r Primary partition(3) type: 131(0x83)(Linux ext2 filesystem) size: 1004mb #s(2056256) s(4919781-6976036) chs: (306/61/49)-(434/60/47)d (306/61/49)-(434/60/47)r Primary partition(4) type: 000(0x00)(unused) size: 0mb #s(0) s(0-0) chs: (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r |
As you see, primary partition can be recovered, but for extended ones it's still to be done.
Dos partitions are labeled “windows NTFS” because they were created while trying to install Windows 2000 (a very awful experience!). The “invalid” one is, in fact the extended partition.
With this, one can use fdisk and try re-creating the partition table (remember, this is risk-free given the original one is already lost).
gpart is updated on a weekly basis :-) and so new makes may be more powerful than I know.
dd if=/dev/hd?? of=/tmp/recover_hd?? bs=512 skip=XXXX count=YYY |
XXX is the sector start and YYY the sector count (can be guessed).
mount -r -t ext2 -o loop /tmp/recover_hd?? /mnt/recover |
The author of this HOWTO is Jean-Daniel Dodin. I can be joined at jdanield@dodin.net or at jdanield@linux-france.org.
My web site is at http://www.dodin.net. Linux pages, who are of most interest for you are found at www.linux-france.org/article/jdanield.
I want to thank Rolf Klausen (- not responding - E-mail: rolfk@romsdal.vgs.no http://www2.romsdal.vgs.no/˜rolfk/) who write the previous partition-rescue mini HOWTO even if I rewrite it almost entirely, he had first the good idea. In 2000 He is no more responding to his e-mail. If anybody knows how to contact him, please let me know.
Every other member of the Linux community and everybody who supports Linux and writes documentation and programs for Linux and all the authors of the LDP and virtually any person involved in anything which has to do with Linux. Particularly Linus B. Torvalds - he is _The King_�!!!
I want also to thank Michail Brzitwa <mb@ichabod.han.de> for writing gpart�!
Bryce Nesbitt <bryce at obviously dot com> did a very good job, “Linux own info” is from him as are some minor enhancements.