Subject: bug#22967: parted 3.2 fails to read MBR partition table where parted 2.3 was ok

From: a <[email-masked]>
Date: Wed, 9 Mar 2016 22:33:16 +0000

Hello, (sorry if duplicate, but my previous send doesn't seem to appear 
on the mailing list !)

I got a problem here with my MBR partition table and parted 3.2 which 
only detects a "loop" partition table while 2.3 is ok.

----------------------------------------------------
Things are working perfectly with parted 2.3:

GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA SAMSUNG HD160JJ (scsi)
Disk /dev/sda: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
  1      32.3kB  41.1MB  41.1MB  primary   fat32        hidden
  2      41.1MB  51.6GB  51.5GB  primary   ntfs         boot
  3      51.6GB  72.9GB  21.3GB  primary   ntfs         hidden
  4      72.9GB  160GB   87.1GB  extended               lba
  5      101GB   105GB   4294MB  logical   ntfs
  6      105GB   131GB   25.2GB  logical   ntfs
  7      131GB   156GB   25.2GB  logical   ntfs
  8      156GB   160GB   4345MB  logical   ntfs

Or the same with "parted /dev/sda unit s print":
Model: ATA SAMSUNG HD160JJ (scsi)
Disk /dev/sda: 312581808s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start       End         Size        Type      File system  Flags
  1      63s         80324s      80262s      primary   fat32        hidden
  2      80325s      100743614s  100663290s  primary   ntfs         boot
  3      100743615s  142400159s  41656545s   primary   ntfs         hidden
  4      142400160s  312580095s  170179936s  extended               lba
  5      197243552s  205630014s  8386463s    logical   ntfs
  6      205632063s  254935484s  49303422s   logical   ntfs
  7      254935548s  304094384s  49158837s   logical   ntfs
  8      304094448s  312580095s  8485648s    logical   ntfs

----------------------------------------------------

However, parted 3.2 does not read the partition table properly anymore 
and goes in "loop" mode:

GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA SAMSUNG HD160JJ (scsi)
Disk /dev/sda: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End    Size   File system  Flags
  1      0.00B  160GB  160GB  fat32

Or the same with "parted /dev/sda unit s print":
Model: ATA SAMSUNG HD160JJ (scsi)
Disk /dev/sda: 312581808s
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End         Size        File system  Flags
  1      0s     312581807s  312581808s  fat32

----------------------------------------------------

Note: I am using the GParted Live CD's, booting them, so I have no way 
to test any version of parted other than the ones on these CD's, which 
are 2.3 and 3.2 to date.

----------------------------------------------------

Besides that, lsblk, fdisk, cfdisk, fsdisk all work perfectly:

root@debian:~# lsblk -o name,maj:min,rm,size,ro,type,fstype,label,mountpoint
NAME                        MAJ:MIN RM   SIZE RO TYPE   FSTYPE    LABEL 
        MOUNTPOINT
sda                           8:0    0 149.1G  0 disk
├─sda1                        8:1    0  39.2M  0 part   vfat    DOSGUB4DOS
├─sda2                        8:2    0    48G  0 part   ntfs    WIN7
├─sda3                        8:3    0  19.9G  0 part   ntfs
├─sda4                        8:4    0     1K  0 part
├─sda5                        8:5    0     4G  0 part   ntfs    SWAP_XP
├─sda6                        8:6    0  23.5G  0 part   ntfs    WINAPP_XP
├─sda7                        8:7    0  23.5G  0 part   ntfs    WINAPP_W7
└─sda8                        8:8    0     4G  0 part   ntfs    SWAP_W7
sdb                           8:16   0 698.7G  0 disk   nvidia_raid_member
├─sdb2                        8:18   0     1K  0 part
├─sdb5                        8:21   0  29.5G  0 part   ntfs    DATA
├─sdb6                        8:22   0  98.3G  0 part   ntfs    CD_IMAGE
├─sdb7                        8:23   0     1G  0 part   vfat    DOS_APPS
├─sdb8                        8:24   0 343.6G  0 part   ntfs    SAVE
├─sdb9                        8:25   0  49.3G  0 part   ntfs    VIRTUAL
└─nvidia_deicejfc (dm-0)    254:0    0 698.7G  0 dmraid
   ├─nvidia_deicejfc5 (dm-1) 254:1    0  29.5G  0 dmraid ntfs     DATA
   ├─nvidia_deicejfc6 (dm-2) 254:2    0  98.3G  0 dmraid ntfs     CD_IMAGE
   ├─nvidia_deicejfc7 (dm-3) 254:3    0     1G  0 dmraid vfat 
DOS_APPS     /mnt/dm3
   ├─nvidia_deicejfc8 (dm-4) 254:4    0 343.6G  0 dmraid ntfs     SAVE
   └─nvidia_deicejfc9 (dm-5) 254:5    0  49.3G  0 dmraid ntfs     VIRTUAL
sdc                           8:32   0 698.7G  0 disk   nvidia_raid_member
├─sdc2                        8:34   0     1K  0 part
├─sdc5                        8:37   0  29.5G  0 part   ntfs    DATA
├─sdc6                        8:38   0  98.3G  0 part   ntfs    CD_IMAGE
├─sdc7                        8:39   0     1G  0 part   vfat    DOS_APPS
├─sdc8                        8:40   0 343.6G  0 part   ntfs    SAVE
├─sdc9                        8:41   0  49.3G  0 part   ntfs    VIRTUAL
└─nvidia_deicejfc (dm-0)    254:0    0 698.7G  0 dmraid
   ├─nvidia_deicejfc5 (dm-1) 254:1    0  29.5G  0 dmraid ntfs     DATA
   ├─nvidia_deicejfc6 (dm-2) 254:2    0  98.3G  0 dmraid ntfs     CD_IMAGE
   ├─nvidia_deicejfc7 (dm-3) 254:3    0     1G  0 dmraid vfat 
DOS_APPS     /mnt/dm3
   ├─nvidia_deicejfc8 (dm-4) 254:4    0 343.6G  0 dmraid ntfs     SAVE
   └─nvidia_deicejfc9 (dm-5) 254:5    0  49.3G  0 dmraid ntfs     VIRTUAL
sr0                          11:0    1  1024M  0 rom
sr1                          11:1    1   195M  0 rom    udf 
GParted-live /lib/live/mount/medium
loop0                         7:0    0 164.1M  1 loop   squashfs 
          /lib/live/mount/rootfs/filesystem.squashfs

============================================

root@debian:~# fdisk -l -u /dev/sda

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x165e165e

    Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63       80324       40131   1b  Hidden W95 FAT32
/dev/sda2   *       80325   100743614    50331645    7  HPFS/NTFS/exFAT
/dev/sda3       100743615   142400159    20828272+  17  Hidden HPFS/NTFS
/dev/sda4       142400160   312580095    85089968    f  W95 Ext'd (LBA)
/dev/sda5       197243552   205630014     4193231+   7  HPFS/NTFS/exFAT
/dev/sda6       205632063   254935484    24651711    7  HPFS/NTFS/exFAT
/dev/sda7       254935548   304094384    24579418+   7  HPFS/NTFS/exFAT
/dev/sda8       304094448   312580095     4242824    7  HPFS/NTFS/exFAT

============================================

sfdisk is ok also:

root@debian:~# sfdisk -l -u s /dev/sda
unrecognized format - using sectors

Disk /dev/sda: 19457 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

    Device Boot    Start       End   #sectors  Id  System
/dev/sda1            63     80324      80262  1b  Hidden W95 FAT32
/dev/sda2   *     80325 100743614  100663290   7  HPFS/NTFS/exFAT
/dev/sda3     100743615 142400159   41656545  17  Hidden HPFS/NTFS
/dev/sda4     142400160 312580095  170179936   f  W95 Ext'd (LBA)
/dev/sda5     197243552 205630014    8386463   7  HPFS/NTFS/exFAT
/dev/sda6     205632063 254935484   49303422   7  HPFS/NTFS/exFAT
/dev/sda7     254935548 304094384   49158837   7  HPFS/NTFS/exFAT
/dev/sda8     304094448 312580095    8485648   7  HPFS/NTFS/exFAT

root@debian:~# sfdisk -l -u S -x /dev/sda

Disk /dev/sda: 19457 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

    Device Boot    Start       End   #sectors  Id  System
/dev/sda1            63     80324      80262  1b  Hidden W95 FAT32
/dev/sda2   *     80325 100743614  100663290   7  HPFS/NTFS/exFAT
/dev/sda3     100743615 142400159   41656545  17  Hidden HPFS/NTFS
/dev/sda4     142400160 312580095  170179936   f  W95 Ext'd (LBA)

/dev/sda5     197243552 205630014    8386463   7  HPFS/NTFS/exFAT
     -         205632000 254935484   49303485   5  Extended
     -         142400160 142400159          0   0  Empty
     -         142400160 142400159          0   0  Empty

/dev/sda6     205632063 254935484   49303422   7  HPFS/NTFS/exFAT
     -         254935485 304094384   49158900   5  Extended
     -         205632000 205631999          0   0  Empty
     -         205632000 205631999          0   0  Empty

/dev/sda7     254935548 304094384   49158837   7  HPFS/NTFS/exFAT
     -         304094385 312580095    8485711   5  Extended
     -         254935485 254935484          0   0  Empty
     -         254935485 254935484          0   0  Empty

/dev/sda8     304094448 312580095    8485648   7  HPFS/NTFS/exFAT
     -         304094385 304094384          0   0  Empty
     -         304094385 304094384          0   0  Empty
     -         304094385 304094384          0   0  Empty

root@debian:~# sfdisk -V /dev/sda
Warning: partition 4 does not end at a cylinder boundary
Warning: partition 5 does not start at a cylinder boundary
Warning: partition 5 does not end at a cylinder boundary
Warning: partition [8] does not end at a cylinder boundary
Warning: partition 8 does not end at a cylinder boundary
/dev/sda: OK

============================================

I suspect the problem is with my MBR contents ...It has Grub4dos in 
there, to multiboot between my DOS, XP and Win7 partitions.
Problem is happening whether it is version 0.4.5c o 0.4.6a.

In case that can help, here is the contents of my /dev/sda MBR

root@debian:~# dd if=/dev/sdc bs=512 count=1 | hexdump -C
1+0 records in
1+0 records out
512 bytes copied, 0.000732162 s, 699 kB/s
00000000  eb 5e 80 00 20 39 ff ff  00 00 00 00 02 01 63 00  |.^.. 
9........c.|
00000010  02 00 00 00 00 f8 00 00  3f 00 ff 00 00 00 00 00 
|........?.......|
00000020  c5 39 01 00 6a 02 00 00  00 00 00 00 02 00 00 00 
|.9..j...........|
00000030  01 00 06 00 00 00 00 00  00 00 00 00 00 00 00 00 
|................|
00000040  80 00 29 7b 3c d6 9c 4e  4f 20 4e 41 4d 45 20 20  |..){<..NO 
NAME  |
00000050  20 20 46 41 54 33 32 20  20 20 00 00 00 00 00 00  |  FAT32 ......|
00000060  fa 31 db 8e d3 bc 80 05  e8 00 00 5b 81 eb 6b 00 
|.1.........[..k.|
00000070  c1 eb 04 8c c8 01 c3 8e  db 53 6a 7d cb 68 00 20 
|.........Sj}.h. |
00000080  17 bc 00 90 fb 16 07 b9  12 00 b8 01 02 89 cb 4b 
|...............K|
00000090  c1 e3 09 ba 80 00 51 53  e8 a4 00 5b 59 72 04 e2 
|......QS...[Yr..|
000000a0  e9 f6 dc 0e 1f 9c 31 f6  31 ff b9 df 00 fc f3 a5 
|......1.1.......|
000000b0  bb fc 1f 66 b8 05 4d cb  93 66 39 07 75 03 e8 39 
|...f..M..f9.u..9|
000000c0  1c ea c6 00 00 20 16 1f  66 39 07 74 28 66 60 bf  |..... 
..f9.t(f`.|
000000d0  03 00 b8 11 02 99 bb 00  02 b9 02 00 e8 80 00 73 
|...............s|
000000e0  02 75 ef 66 61 66 39 07  75 4d c7 06 06 00 00 ff 
|.u.faf9.uM......|
000000f0  80 26 02 00 fe 9d 72 33  0e 1f ad 88 e6 ad 89 c1 
|.&....r3........|
00000100  24 3f 74 14 b0 01 bf 03  00 b4 02 68 00 0d 07 31 
|$?t........h...1|
00000110  db e8 4b 00 73 03 75 f1  f9 e8 5c 11 0f 87 f3 1b 
|..K.s.u...\.....|
00000120  83 c6 0c 81 fe fe 01 72  cf 77 0c be b2 31 b0 04 
|.......r.w...1..|
00000130  b9 01 00 31 d2 eb cf be  91 01 e8 4d 00 eb fe 1e 
|...1.......M....|
00000140  06 52 56 57 55 f9 cd 13  5d 5f 5e 5a 07 1f c3 fa 
|.RVWU...]_^Z....|
00000150  b8 00 20 8e d0 bc dc 8f  fb 66 61 07 1f eb c1 60  |.. 
......fa....`|
00000160  50 53 51 fe c8 00 c1 d0  e0 00 c7 b0 01 e8 cf ff 
|PSQ.............|
00000170  59 5b 58 72 04 fe c8 75  e7 61 73 09 60 31 c0 e8 
|Y[Xr...u.as.`1..|
00000180  bd ff 61 4f f9 c3 b4 0e  cd 10 2e ac 3c 00 75 f6 
|..aO........<.u.|
00000190  c3 0d 0a 4d 69 73 73 69  6e 67 20 4d 42 52 2d 68  |...Missing 
MBR-h|
000001a0  65 6c 70 65 72 2e 00 00  00 00 00 00 00 00 00 00 
|elper...........|
000001b0  00 00 00 00 00 00 00 00  5e 16 5e 16 00 00 00 01 
|........^.^.....|
000001c0  01 00 1b fe 3f 04 3f 00  00 00 86 39 01 00 80 00 
|....?.?....9....|
000001d0  01 05 07 fe ff ff c5 39  01 00 fa ff ff 05 00 fe 
|.......9........|
000001e0  ff ff 17 fe ff ff bf 39  01 06 e1 a0 7b 02 00 fe 
|.......9....{...|
000001f0  ff ff 0f fe ff ff a0 da  7c 08 60 bd 24 0a 55 aa 
|........|.`.$.U.|
00000200

----------------------------------------------------

So I am at a loss .. what is going wrong which makes parted 3.2 not 
interpret my partition table correctly, while parted 2.3 is ok ?
How should I correct things ? (or is there a bug in parted 3.2 ??)

Thank you in advance for any feedback .. or ready to provide more if you 
suspect a problem in parted 3.2.

Thanks, and best regards, Erwin9