Partition-Rescue HOWTO

Jean-Daniel Dodin

Revision History
Revision v3.42002-08-22Revised by: jdd
Minor update related only with docbook
Revision v3.32001-11-17Revised by: jdd
Minor update - docbook & revision history - emacs use.
Revision v3.22001-09-25Revised by: jdd
Major update.

Table of Contents
1. Beginning
1.1. What's in
1.2. What to do right now ?
1.3. Legal stuff
1.4. What do I must know right now?
2. Technical info
2.1. Disks
2.2. Partitions
2.3. Why is there a problem ?
3. Solving the problem
3.1. The simpler case
3.2. A not so simple case
3.3. The rich man case
4. References
4.1. Authors
4.2. Most recent version

1. Beginning

2. Technical info

2.2. Partitions

Disk are now huge, 40 Gb are not rare, so that it's not really handy to have all this stuff packed in only one part. Only Windows do so, and if you use Linux, may be it's because you are aware of how inefficient the other is.

So a hard disk is usually cut in some pieces called “partitions” (see the “partition HOWTO” for details, also read /usr/share/doc/package/util/README.fdisk)

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.

There can be four of such primary partitions. If one wants more than 4, one of them must be an “extended” one (not necessarily the fourth) and all other partitions are named “logical” and are located inside the extended one. Notice that partition number 5 and partition number 4 have the same beginning. Number five is logical, number 4 extended. Logicals begin always at 5, even if there are not 4 primary ones.

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.

Don't worry for the french part, I'm french... look at your own disk listing. Of course numbers are bigger.

3. Solving the problem

Please, beware! following the explanations given here will lead you to turn back to a previous system, loosing all your recent installed one, if any! You must choose...

3.1. The simpler case

All is simple if you have at hand :

It's enough to

  1. start Linux ;

  2. start fdisk /dev/hda (or whatever is the disk to rescue) ;

  3. use fdisk to delete (d option) all the existing partitions on the damaged disk ;

  4. use fdisk to create all the primary (1-4) partition mentioned on the paper ;

  5. give them the appropriate tag (t option) : 82 is for Linux swap, 83 for Linux main (L gives you the list), 5 is extended and must be done before creating logical partitions, c is Windows Fat 32 and f Windows extended when 6 is Windows Fat 16.

  6. create any logical partition.

On my SuSE installation and anytime I had to do this for other peoples, this gives a good result.

However I was said that some fdisk may cut partitions on a sector basis, not cylinder. So the fdisk -u -l version of the paper.

For using the fdisk -u -l listing one must start fdisk -u :-). On my opinion, using sector limit is a very bad idea, but it may have a real use I'm not aware of. Problem is that with cylinder limit it's easy to guess even if you don't have paper. With sector one, there a many more guesses...

fdisk is a small and very smart programs. There are many other makes of fdisk, but I always prefer the bare bone one (I speak of Linux ones, of course, not the others...).

Be aware that fdisk doesn't write anything to disk before you hit w and return. In case you fear a mistake, hit q (quit) or Ctrl C (^C) to quit safe.

When your new partition table is written, start your Linux. Chance is you can't do that as usual: lilo can have been damaged also and you will need a boot floppy or booting from a CD (choose the option “booting the installed partition”).

If you use to boot with lilo, as soon as you are logged in as root, key in “lilo” and hit return to reinstall you favorite boot loader.

Your Linux should be all here, test it. Try also to start Windows if applicable. If you can't, there is a (very little) chance you can read your data from Linux, may be with a raw sector by sector read. If you can identify the disk sectors you data is on, using dd can copy them on a file. This is wise for text only. This recovery is NOT in the scope of this mini-HOWTO.

3.2. A not so simple case

3.2.2. Linux own info and other hacks

3.2.3. gpart

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 or directly at

“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 
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.

4. References

4.1. Authors

The author of this HOWTO is Jean-Daniel Dodin. I can be joined at or at

My web site is at Linux pages, who are of most interest for you are found at

I want to thank Rolf Klausen (- not responding - E-mail:˜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 <> 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.