Subject: Re: bug#18984: Enhancement request: Handling of damaged partition tables

From: Phillip Susi <[email-masked]>
Date: Mon, 10 Nov 2014 13:15:06 -0500

On 11/7/2014 10:12 AM, Ulrich Windl wrote:
> I have a system that features a damaged partition table for an 1TB
> disk with 4kB sectors. While Windows 7 boot without any complaint,
> and diskpart is happy, GNU parted doesn't display the existing
> partitions, because it says there are overlapping partitions. This
> in turn causes every Linux system I tried to install to overwrite
> the existing partitions, because they are not detected by parted!

<snip>

> Model:  (file) Disk /home/user/Projekte/sect0.0: 4096B Sector size
> (logical/physical): 512B/512B Partition Table: msdos Disk
> Flags:=20
> 
> Number  Start   End     Size   Type      File system  Flags 1
> 1049kB  103GB   103GB  primary 2      103GB   318GB   215GB
> primary 3      318GB   1000GB  682GB  extended               lba 4
> 855GB   962GB   107GB  primary                boot
> 
> (parted) version

That looks like it is detecting and displaying the partitions to me.

> 1) Instead of saying "Can't have a partition outside the disk!"
> say _which_ partition you think is outside the disk, and say _why_
> you think so.

I suppose that could be nice, though when you print the table and have
a look for yourself it isn't hard to figure out.  In your case your
"disk" is only one sector long so everything is outside of that.

> 2) Despite of the message "Invalid partition table on
> /home/wiu09524/Projekte/sect0.0 -- wrong signature 0." the MBR 
> signature is 0x55, 0xaa as expected

It is talking about the extended partition table which it sees as all
zeroes since you don't have it in the image file, the read failed, and
you chose to ignore that failure.

> 3) Instead of saying "Can't have overlapping partitions." say
> _which_ partitions you think overlap with which other partitions,
> and perferrably give precise data for the overlap. Parted should
> not just help secretaries, but technicals also ;-)

Same as above: might be nice but it's pretty easy to figure out by
looking at the output of print.

> 4) "Can't have a primary partition inside an extended partition."
> may be true, but see 3) for proposed improvements.
> 
> So here comes my own decoding of the MBR (cant' decode extended 
> partitions, because I only have an image of the first 4kB sector
> here):
> 
> First the four partition table entries as byte dump (for the
> gurus): partition #1: 80 fe ff ff 07 fe ff ff 00 58 80 63 00 38 80
> 0c partition #2: 00 7b cb ff 0f fe ff ff 00 48 00 25 00 b8 6f 4f 
> partition #3: 00 fe ff ff 07 fe ff ff 00 48 00 0c 00 00 00 19 
> partition #4: 00 20 21 00 07 fe ff ff 00 08 00 00 00 40 00 0c
> 
> Next the table entries decoded (partition type and active flag in
> hex, then C/H/S of start, C/H/S of end, LBA of start, LBA of end):
> 
> partition #1:  7 80 1023/254/63 1023/254/63 1669355520  209729536 
> partition #2:  f 00 1023/123/11 1023/254/63  620775424 1332721664 
> partition #3:  7 00 1023/254/63 1023/254/63  201345024  419430400 
> partition #4:  7 00    0/ 32/33 1023/254/63       2048  201342976
> 
> Finally everything converted to LBAs and then to GB (1024^2 kB): 
> partition #1:    7.875    7.875  796.011  100.007 (   0.000 /
> -696.004) partition #2:    7.871    7.875  296.009  635.491 (
> 0.004 /  339.482) partition #3:    7.875    7.875   96.009  200.000
> (   0.000 /  103.991) partition #4:    0.001    7.875    0.001
> 96.008 (   7.874 /   96.007)
> 
> You see that partition #1 (the last entry in the table) features a 
> negative size!

There is no such thing as a negative size since the table lists the
start and length ( not end ) as unsigned dwords.

> It would be great if parted could not only complain, but also
> suggest how to fix the problems detected, just like fsck does for
> years.

The fix should be obvious: delete one of the overlapping partitions,
or shrink the first one.  How to do that safely is too involved to
suggest in a short error message.