Gpart


gpart is a software utility which scans a storage device, examining the data in order to detect partitions which may exist but are absent from the disk's partition tables. Gpart was written by Michail Brzitwa of Germany. The release on the author's website is now older than the releases some distributions are using. It appears that Michail Brzitwa does not actively maintain the code, instead the various distributions appear to maintain their own versions.
gpart tries to guess partitions from any device that can be partitioned, even a file. If the primary partition table has been lost, overwritten or destroyed the partitions still exist on the media but the operating system cannot access them.
gpart ignores the primary partition table and scans the disk sector after sector for several filesystem/partition types. It does so by "asking" filesystem recognition modules if they think a given sequence of sectors resembles the beginning of a filesystem or partition type.

Michail Brzitwa,: "gpart - Linux man page", January 2001
A list of these modules are listed below. Also modules can be written for future filesystems and used in the detection process.
If recovering partitions is needed that are damaged on the only bootable disk in a machine, a live CD can be used such as knoppix to start the machine and use the utilities from the disk.
It is also good at finding and listing the types, locations, and sizes of inadvertently-deleted partitions, both primary and logical. It gives you the information you need to manually re-create them. The guessed partition table can also be written to a file or directly to a disk device.
With some badly damaged devices it is a good idea to use a utility such as ddrescue to make a backup. Then when you have a copy of the device, use gpart to guess the partitions on the copy. If it is successful, you can try writing them back to the device. You may find that when using ddrescue you get read errors because the device is damaged but if you can get the partitions readable with your copy then you can try using Mount (Unix) and retrieve the data from the copy.
$ mount -t /path/to/imagefile -o loop,offset= /mnt/loop
This will mount the partition at offset on /mnt/loop so you can recover your data from the file.
To get the partition offset you can use either fdisk -ul /path/to/imagefile or use the output from gpart.
Look at the sample output at the size line, the last pair of round brackets has the start and then end.
When specifying the offset, always specify the start.

Sample output

This is sample output from a scan of an 8GB flash memory stick with two partitions, one FAT16B 2GB partition and one xfs 6GB partition.
Begin scan...
Possible partition, size, offset
Possible partition, size, offset
End scan.

Checking partitions...
Partition : primary
Partition : primary
Ok.

Guessed primary partition table:
Primary partition
type: 012
size: 1907mb #s s
chs: -d -r

Primary partition
type: 131
size: 5730mb #s s
chs: -d -r

Primary partition
type: 000
size: 0mb #s s
chs: -d -r

Primary partition
type: 000
size: 0mb #s s
chs: -d -r

Partition types

Supported filesystem or partition types: