gpart Logo
 
Download First Aid Man-Page Links German Changes Author
gpart - Guess PC-type hard disk partitions
Gpart is a tool which tries to guess the primary partition table of a PC-type hard disk in case the primary partition table in sector 0 is damaged, incorrect or deleted. The guessed table can be written to a file or device. Supported (guessable) filesystem or partition types: 
 
  • DOS/Windows FAT (FAT 12/16/32)
  • Linux ext2
  • Linux swap partitions versions 0 and 1 (Linux >= v2.2.X)
  • OS/2 HPFS
  • Windows NTFS
  • *BSD disklabels
  • Solaris/x86 disklabels
  • Minix FS
  • Reiser FS
  • Linux LVM physical volume module (LVM by Heinz Mauelshagen) 

Download
Current gpart source: gpart-0.1f.tar.gz
Statically linked Linux binary (160 KBytes): gpart.linux
Statically linked FreeBSD binary (70 KBytes): gpart.freebsd

First Aid
If you're trying to rescue a system with a corrupted partition table on the main (boot) disk which is unable to boot you have two options:
  • the easiest way is to find a working system where you can add your disk. In case the other system cannot report the disk's correct geometry, note down its geometry prior to moving to the working system and tell gpart about it (use the "-C c,h,s" option).
  • download the gpart binary above, rename it to "gpart", store it on a floppy disk, print out the manual page above, and start your system by using your prefered boot disk.
After booting, look if your hard disk has been detected by your system by entering a shell and typing "dmesg". Under e.g. Linux you should look out for lines like "hdc: ST320430A, 19569MB w/512kB Cache, CHS=39761/16/63". If you have booted with a rescue disk mount the floppy disk with gpart on, and cd to the mount point.

Now run "gpart /dev/<your disk>", e.g. "gpart /dev/hdc". Without any options, gpart performs a standard scan, and merely looks if it can guess a consistent primary partition table. A typical positive output looks like:

Begin scan...
Possible partition(DOS FAT), size(3999mb), offset(0mb)
Possible extended partition at offset(4000mb)
  Possible partition(Windows NTFS), size(3999mb), offset(4000mb)
  Possible partition(Linux ext2), size(3072mb), offset(8000mb)
  Possible partition(Linux ext2), size(3072mb), offset(11072mb)
Possible partition(Linux ext2), size(3072mb), offset(14144mb)
Possible partition(Linux ext2), size(2353mb), offset(17216mb)
End scan.

Checking partitions...
Partition(DOS or Windows 95 with 32 bit FAT): primary
  Partition(OS/2 HPFS, NTFS, QNX or Advanced UNIX): logical
  Partition(Linux ext2 filesystem): logical
  Partition(Linux ext2 filesystem): logical
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Ok.

Guessed primary partition table:
Primary partition(1)
  type: 011(0x0B)(DOS or Windows 95 with 32 bit FAT)
  size: 3999mb #s(8191953) s(63-8192015)
  chs:  (0/1/1)-(1023/15/63)d (0/1/1)-(8126/15/63)r

Primary partition(2)
  type: 005(0x05)(Extended DOS)
  size: 10144mb #s(20775888) s(8192016-28967903)
  chs:  (1023/15/63)-(1023/15/63)d (8127/0/1)-(28737/15/63)r

Primary partition(3)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 3072mb #s(6291456) s(28967904-35259359)
  chs:  (1023/15/63)-(1023/15/63)d (28738/0/1)-(34979/8/24)r

Primary partition(4)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 2353mb #s(4819248) s(35259840-40079087)
  chs:  (1023/15/63)-(1023/15/63)d (34980/0/1)-(39760/15/63)r

Now if after the check-phase it says Ok, you should check the proposed partition table very carefully. After that you may write back the guessed table by calling "gpart -W /dev/hdc /dev/hdc" (exchange /dev/hdc with your disk device). When gpart has successfully written the new primary partition table, cross your fingers and reboot.

If gpart says it found inconsistencies, you are a bit on your own. What you can do is to fiddle with gparts numerous options. For example, to scan on sector boundaries instead of head boundaries, give it the "-n s" option. Normally gpart skips the disk space a possible partition seems to occupy, to really scan the whole disk, add the "-f" option. Read the man page and improvise.

In case gpart fails completely I can only point out some other similar tools which may help you. There is a tool called rescuept by Andries Brouwer which is included in the non-installed part of util-linux (you can find them on almost every Linux ftp site). Another tool is Gordon Chaffees fixdisktable. Good luck.

Links

Changes
v0.1f:
  • Default scan increment 'h' again.
  • Fixed wrong head-boundary condition.
  • Introduced possibility to edit guessed partitions.
  • Scan now starts on (sectors/head) unless -k was given.
  • Length of guessed NTFS partitions now includes NTFS backup boot sector.
v0.1e:
  • Default scan increment now 's', extended ptbl boundary condition now depends on scan increment (head if 's', else cylinder boundary).
  • Added LVM physical volume module (LVM by Heinz Mauelshagen, see http://linux.msede.com/lvm).
v0.1d:
  • Cope with short reads/read errors from disk (corrupted sectors etc.).
  • When flagging probable partitions 'invalid' give a reason why (use -vv). 
v0.1c:
  • Don't flag partitions 'invalid' which are smaller than their partition table entry.
  • Fixed buggy rejection of some valid ext2 superblocks.
  • Fixed Linux swap partition size calculation.
  • Added Reiser FS module. 
v0.1b:
  • First public version.
  • Made 'fast' scan the default behaviour (-f enables the complete scan).
  • Increased tolerance in recognizing extended partition tables. 
v0.1a:
  • Initial version.

Author
If you have comments, suggestions, problems with gpart or bug reports, contact me,
Michail Brzitwa
Last update: 4. March 2000


 
Bobby Approved (v 3.1)