Skip to content

Instantly share code, notes, and snippets.

@leodutra
Created March 8, 2017 13:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodutra/8779d468e9062058a3e90008295d3ca6 to your computer and use it in GitHub Desktop.
Save leodutra/8779d468e9062058a3e90008295d3ca6 to your computer and use it in GitHub Desktop.
Bios boot type on GPT vs MBR boot flag
  • Legacy BIOS bootable attribute -- This is the official name of the relevant feature, as described in the UEFI specification (version 2.3.1, p. 105, Table 19). It's set by setting the "legacy_boot flag" in parted or its relatives, or by setting attribute bit #2 using the "a" option on the experts' menu in gdisk. (The wiki to which you linked describes doing this with sgdisk.) It's used by SYSLINUX's GPT support to identify a partition that holds second-stage boot code.
  • The "boot flag" on MBR disks -- On MBR disks, the "boot flag" is a bit that can be set using either fdisk or parted. It's analogous to the GPT legacy BIOS bootable attribute, since it serves the same purpose. Note that on a GPT disk, it's possible (although technically a violation of the spec) to set this flag on the protective 0xEE partition. You can do this with fdisk, but not with parted, since the latter lacks a user interface to do anything explicit with the protective 0xEE MBR partition. (This is reportedly changing with in-development versions of parted, but AFAIK the changed version hasn't been released.) Some buggy BIOSes require the MBR boot flag to be set on the 0xEE protective partition to boot the disk in BIOS mode.
  • The parted "boot flag" on GPT disks -- This is parted's way of identifying an EFI System Partition (ESP), and it has nothing to do with either the legacy BIOS bootable attribute or an MBR boot flag. This "flag" really changes the partition type code. gdisk reports a partition on which parted has set this "flag" as having a type code of EF00.
@johnlane
Copy link

johnlane commented Jul 4, 2018

To set the protective MBR's boot flag with parted:

(parted) disk_set pmbr_boot on

As far as I can tell there is no way with contemporary fdisk or even gdisk to set the boot flag on an MBR partition, be that hybrid or protective. Trying to find such a way landed me on your gist.

@andy-shev
Copy link

@johnlane

To set the protective MBR's boot flag with parted:

(parted) disk_set pmbr_boot on

As far as I can tell there is no way with contemporary fdisk or even gdisk to set the boot flag on an MBR partition, be that hybrid or protective. Trying to find such a way landed me on your gist.

It kills the partition table on PMBR. I have two and this makes it one. Especially taking into consideration that a) I have hybrid MBR and b) I need to set active on the second partition. So, I become with a bit dirtier (b/c no special tools it used) but working solution:

# Set 'active" flag for partition 2 on protective MBR (sgdisk may not do this)
printf '\200' | dd of=$image bs=1 seek=462 conv=notrunc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment