gpart - guess PC-type hard disk partitions
Options: [-b <backup MBR>][-C c,h,s][-c][-d][-E][-e][-f] [-g][-h][-i][-K <last-sector>][-k <# of sectors>] [-L] [-l <log file>][-n <increment>] [-q][-s <sector-size>] [-t <module-name>][-V][-v] [-W <device>][-w <module-name, weight>]
gpart ignores the primary partition table and scans the disk (or disk image, file) 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. Currently the following filesystem types are known to gpart (listed by module names) :
More filesystem guessing modules can be added at runtime (see the -t option). Please consult the gpart README file for detailed explanations on how to create guessing modules. All modules are accompanied by a guessing weight factor which denotes how "educated" their guesses are compared to other modules. This weight can be changed if a certain module keeps on mis-identifying a partition.
Naturally only partitions which have been formatted in some way can be recognized. If the type of a partition entry in the primary partition table is changed from x to y while the filesystem is still of type x, gpart will also still guess a type x.
No checks are performed whether a found filesystem is clean or even consistent/mountable, so it is quite possible that gpart may identify partitions which existed prior to the current partitioning scheme of the disk. Especially on large disks old file system headers/superblocks may be present a long time until they are finally overwritten with user data.
It should be stressed that gpart does a very heuristic job, never believe its output without any plausability checks. It can be easily right in its guesswork but it can also be terribly wrong. You have been warned.
After having found a list of possible partition types, the list is checked for consistency. For example, a partition which overlaps with the previous one will be discarded. All remaining partitions are labelled with one of the following attributes: "primary", "logical", "orphaned" or "invalid".
A partition labelled "orphaned" is a logical partition which seems ok but is missed in the chain of logical partitions. This may occur if a logical partition is deleted from the extended partition table without overwriting the actual disk space.
An "invalid" partition is one that cannot be accepted because of various reasons. If a consistent primary partition table was created in this process it is printed and can be written to a file or device.
Extended partitions are realized as a linked list of extended partition tables, each of which include an entry pointing to a logical partition. The size of an extended partition depends on where the last logical partition ends. This means that extended partitions may include "holes", unallocated disk space which should only be assigned to logical, not primary partitions.
gpart tries to do its best to check a found chain of logical partitions but there are very many possible points of failure. If "good" fdisk programs are used to create extended partitions, the resulting tables consist of a zeroed boot record and the four partition entries of which at least two should be marked unused. Unfortunately e.g. the fdisk program shipped with Windows NT does not seem to zero out the boot record area so gpart has to be overly tolerant in recognizing extended partition tables. This tolerance may result in quite stupid guesses.
Investigating disks from machines with a different endianness than the scanning one has not been tested at all, and is currently not recommended.
gpart checks if guessed partitions extend beyond the disk size and marks those "invalid", but may be mistaken in case the disk size is calculated from an incorrect geometry. For instance if a disk with the geometry 1028/255/63 should be scanned, and the OS reports 1024/255/63 gpart should be called like
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
Warning: make sure that all parameters are typed as shown and that the disk device is correct. Failing to do so may result in severe filesystem corruption. The saved file should be stored in a safe place like a floppy disk.
The increment also influences the condition where extended partition tables are searched: if the scan increment is "s" (i.e. 1) extended partition tables are required to be on a head boundary, otherwise they must be on a cylinder boundary.
If the disk geometry could not be retrieved and no geometry was given on the command line, the default increment is one sector.
Additionally the guessed partition entries can be edited. No checks are performed on the entered values, thus the resulting table is allowed to be highly inconsistent. Please beware.
Warning: The guessed partition table should be checked very carefully before writing it back. You can always write the guessed partition table into a plain file and write this into sector 0 using dd(1) (see section PRECAUTIONS above).
Default settings are "-n h".
- To print the primary partition table of the third IDE drive without starting the scan loop in FreeBSD type
- If lilo(8) was installed in the master boot record (MBR) of a hard disk it saves the contents of the first sector in a file called /boot/boot.<major/minor>. To list the partitions contained in such a file type e.g.
If the partition table contains an extended partition, gpart will complain about invalid extended partition tables because the extended entry points to sectors not within that file.
- Usually the first primary partition starts on the second head. If gpart cannot identify the first partition properly this may not be the case. gpart can be told to start the scan directly from sector one of the disk, using the sector-wise scan mode:
- 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:
To list the available modules and their weights use the -L option.
- After having checked the output of gpart at least thrice, the primary partition table can be written back to the device this way:
This of course may be extremely dangerous to your health and social security, so beware.
- A hard disk with 63 sectors per head is scanned in steps of 63 sectors. To perform the scan on every second head while skipping the first 1008 sectors type
- If you want to see how easily gpart can be mislead, and how many probable partition starts are on a disk, search the whole disk really sector by sector, writing all output to a logfile:
Usually gpart will not be able to produce an educated guess of the primary partition table in this mode. The logfile however may contain enough hints to manually reconstruct the partition table.
- gpart only accepts extended partition links with one logical partition. There may be fdisk variants out there creating links with up to three logical partition entries but these are not accepted.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |