Yes, as long as your system is up, almost all information is still there.
Suppose you want to use sfdisk to create a partition table.
It takes as input a table like
# partition table of /dev/hdb
unit: sectors
/dev/hdb1 : start= 63, size= 112392, Id=83
/dev/hdb2 : start= 112455, size= 289170, Id=82
/dev/hdb3 : start= 401625, size=33334875, Id= 5
/dev/hdb4 : start= 0, size= 0, Id= 0
/dev/hdb5 : start= 401688, size=15663312, Id=83
/dev/hdb6 : start= 16065064, size= 8032436, Id=83
/dev/hdb7 : start= 24097564, size= 9638936, Id=83
So, you need start and size and type of each partition.
There are many ways to find the start and size of a partition.
(The kernel will tell it you if you invoke the HDIO_GETGEO
and BLKGETSIZE ioctls.
So, either write the three-line C program or find a utility
that does this already.)
For example,
% /sbin/hdparm -g /dev/hdb1
/dev/hdb1:
geometry = 2100/255/63, sectors = 112392, start = 63
% /sbin/hdparm -g /dev/hdb3
/dev/hdb3:
geometry = 2100/255/63, sectors = 2, start = 401625
(And if you forgot which partitions you had, try
cat /proc/partitions
if you have a recent kernel.)
Remain two problems:
(i) The types - these are not recorded anywhere, so must be regarded lost.
Use 83 for Linux fs, 82 for Linux swap, fd for Linux raid autodetect.
Use 5 for an extended partition, recognizable because /proc/partitions
gives the size as 1 (block) and hdparm gives the size as 2 (sectors).
Look at
http://www.win.tue.nl/~aeb/partitions/partition_types-1.html
for all other possible partition types
(and tell me if you know about types I missed).
(ii) The size of your extended partition.
You'll have to compute that yourself by subtracting its start from the start
of the next partition or the end of the disk.
For example,
% cat /proc/partitions | grep hdb
3 64 16875432 hdb
3 65 56196 hdb1
3 66 144585 hdb2
3 67 1 hdb3
3 69 7831656 hdb5
3 70 4016218 hdb6
3 71 4819468 hdb7
hdb3 is extended, hdparm told us that it starts at sector 401625,
the entire disk has 16875432 blocks, that is 33750864 or 33750865
sectors, so the size of hdb3 should be 33750864 - 401625 = 33349239 sectors.
(Without /proc/partitions you also find the disk size from "hdparm -i"
by looking at the LBAsects=33750864 entry.)
But above I showed that hdb3 has size 33334875?
The fdisk that made it let it end at a cylinder boundary.
With C/H/S = 2100/255/63 a cylinder has 255*63=16065 sectors (8.2 MB);
the start of hdb3 is at the 25 cylinder mark (25*16065=401625)
and the end at the 2100 cylinder mark, so that the size is
2075*16065=33334875 sectors.
In fact there is still room for a 14364 sector partition (7.4MB)
and the end of the disk.
Andries - aeb@cwi.nl
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/