Subject: bug#33607: Partition list loop

From: Paul Ausbeck <[email-masked]>
Date: Mon, 3 Dec 2018 21:04:19 -0800

I have a disk with three primary partitions and one extended partition. The extended partition originally contained 4 logical volumes sda5-8. sda5 and sda6 were 16GB, sda7 8GB, and sda8 the balance of the extended partition > 100GB. sda5 and sda6 contained debian jessie x86 and x64 boot filesystems. I wanted to install stretch filesystems on this disk so booting to sda6 I resized sda5 to fit into 8GB. I then used fdisk to delete sda5 and create two new 8GB partitions sda8 and sda9 where the 16GB sda5 formerly resided. When I committed the changes partprobe reported that the new partition table couldn't be read due to partitions being busy and I should reboot. After the reboot everything was as fdisk said it would be, partitions formerly sda6-8 were now sda5-7 and the new partitions were sda8-9.

Now this is where things went off the rails. I decided that before making any more changes I would reorder the partition table to be in disk order, using fdisk's extended command, x, then f. After fixing the partition order, fdisk listed all nine partitions in partition order. I then committed the changes and again got the partprobe message that I should reboot. Well, at this point the drive would not boot properly. The linux kernel loads but partprobe is looping through the logical partitions again and again and creating many copies of the same five partitions, up to a max it looks like of sda255.

If I run parted and try and print the partition table I get the following error:

Assertion (metadata length >0) at .././../libparted/labels/dos.c:2313 in function add_logical_part_metadata() failed.

At this point, I don't know exactly who to blame. Either fdisk has somehow created an unterminated, looping partition list, or parted/partprobe is erroneously processing a correct list. I'm reporting on the parted mailing list as I ran into your assertion and bug report instructions and thought you'd like to know about it.

Personally, I'm thinking that parted/partprobe shouldn't loop back through the same partitions reporting them as additional partitions, even if the partition list is telling them to do so.

Also, I'm hoping that someone on the parted list can tell me how to patch things up with dd.

I can boot from a USB stick and use fdisk to print its idea of the partition table, below.  Parted does not print the table but throws the above assertion. The table:

Command (m for help): p
Disk /dev/sda: 232.9 GiB, 250059350016 bytes, 488397168 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
Disklabel type: dos
Disk identifier: 0xa0e33a5e

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048   2459647   2457600   1.2G  7 HPFS/NTFS/exFAT
/dev/sda2         2459648  84379647  81920000  39.1G  7 HPFS/NTFS/exFAT
/dev/sda3        84379648 166299647  81920000  39.1G  7 HPFS/NTFS/exFAT
/dev/sda4       166299648 488397167 322097520 153.6G  5 Extended
/dev/sda5       166301696 183078911  16777216     8G 83 Linux
/dev/sda6       183080960 199858175  16777216     8G 83 Linux
/dev/sda7       199858176 233412607  33554432    16G 83 Linux
/dev/sda8       233414656 250191871  16777216     8G 82 Linux swap / Solari
/dev/sda9       250193920 488397167 238203248 113.6G 83 Linux