- // Second, do Linux partitions....
- i = 0;
- while (i < gpt_part_count && new_mbr_part_count <= 3) {
+ // Second, do Linux partitions. Note that we start from the END of the
+ // partition list, so as to maximize the space covered by the 0xEE
+ // partition if there are several Linux partitions.
+ i = gpt_part_count - 1; // Note that gpt_part_count can't be 0; filtered by check_gpt()
+ while (i >= 0 && new_mbr_part_count <= 3) {