if (!fdisk_dev_has_disklabel(cxt)) {
fdisk_info(cxt, _("Device does not contain a recognized partition table."));
fdisk_create_disklabel(cxt, NULL);
- }
+
+ } else if (fdisk_is_disklabel(cxt, GPT) && fdisk_gpt_is_hybrid(cxt))
+ fdisk_warnx(cxt, _(
+ "The hybrid GPT detected. You have to sync "
+ "the hybrid MBR manually (expert command 'M')."));
while (1)
process_fdisk_menu(&cxt);
}
fill_bounds(cxt, first, last);
if (n < 4) {
- start = cxt->first_lba;
+ if (cxt->parent && fdisk_is_disklabel(cxt->parent, GPT))
+ start = 1; /* Bad boy modifies hybrid MBR */
+ else
+ start = cxt->first_lba;
+
if (fdisk_context_use_cylinders(cxt) || !cxt->total_sectors)
limit = cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders - 1;
else
static int gpt_write_disklabel(struct fdisk_context *cxt)
{
struct fdisk_gpt_label *gpt;
+ int mbr_type;
assert(cxt);
assert(cxt->label);
assert(fdisk_is_disklabel(cxt, GPT));
gpt = self_label(cxt);
-
- /* we do not want to mess up hybrid MBRs by creating a valid pmbr */
- if (valid_pmbr(cxt) == GPT_MBR_HYBRID)
- goto err0;
+ mbr_type = valid_pmbr(cxt);
/* check that disk is big enough to handle the backup header */
if (le64_to_cpu(gpt->pheader->alternative_lba) > cxt->total_sectors)
goto err1;
if (gpt_write_header(cxt, gpt->pheader, GPT_PRIMARY_PARTITION_TABLE_LBA) != 0)
goto err1;
- if (gpt_write_pmbr(cxt) != 0)
+
+ if (mbr_type == GPT_MBR_HYBRID)
+ fdisk_warnx(cxt, _("The device contains hybrid MBR -- writing GPT only. "
+ "You have to sync the MBR manually."));
+ else if (gpt_write_pmbr(cxt) != 0)
goto err1;
DBG(LABEL, dbgprint("GPT write success"));
return 0;
}
+int fdisk_gpt_is_hybrid(struct fdisk_context *cxt)
+{
+ assert(cxt);
+ return valid_pmbr(cxt) == GPT_MBR_HYBRID;
+}
+
static int gpt_toggle_partition_flag(
struct fdisk_context *cxt,
size_t i,
extern int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i);
extern int fdisk_gpt_partition_set_name(struct fdisk_context *cxt, size_t i);
+extern int fdisk_gpt_is_hybrid(struct fdisk_context *cxt);
/* dos.c */
extern struct dos_partition *fdisk_dos_get_partition(