Notes on working with gpart, the “guess partition” utility
gpart may be of some help when the primary partition table was lost or destroyed but it can under no cir-
cumstances replace proper disk/partition table backups. To save the master boot record (MBR) including
the primary partition table to a file type
dd if=/dev/hda of=mbr bs=512 count=1
exchanging /dev/hda with the block device name of the disk in question. This should be done for all disks
in the system. To restore the primary partition table without overwriting the MBR type
dd if=mbr of=/dev/hda bs=1 count=64 skip=446 seek=446
OPTIONS
-b backupfile
If the guessed primary partition table seems consistent and should be written (see the -W option)
backup the current MBR into the specified file.
-c Check/compare mode (implies the -q quiet option). After the scan is done, the resulting primary
partition table is compared to the existing one. The return code of gpart then contains the number
of differences (0 if they are identical except for the boot/active flag which cannot be guessed).
This option has no effect if -d is given on the command line.
-d Do not start the guessing loop. Useful if the partition table should be printed (in combination
with the -v option) without actually scanning for partitions.
-K last sector
Scan only up to the given sector or the end of the file or device whichever comes first.
-k sectors
Skip given number of sectors before the scan. Potentially useful if a partition is looked for at
the end of a large disk.
- Suppose gpart identifies an NTFS partition as FAT on a certain disk. In this situation the "ntfs" module
should be made the first module to be probed and given a weight higher than the usual weight of 1.0:
gpart -w ntfs,1.5 /dev/hdb
To list the available modules and their weights use the -L option.