Skip to content

Commit

Permalink
Drop old bootflag detection, rely on python3-parted
Browse files Browse the repository at this point in the history
While at it rename "bootflag" into "boot flag" in human readable
strings.

Thanks: Darshaka Pathirana for bug report and debugging
Closes: #19
  • Loading branch information
mika committed May 27, 2020
1 parent 0de90ba commit 5579b7b
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions grml2usb
Expand Up @@ -184,7 +184,7 @@ parser.add_option(
"--skip-bootflag",
dest="skipbootflag",
action="store_true",
help="do not try to check whether the destination has the bootflag set",
help="do not try to check whether the destination has the boot flag set",
)
parser.add_option(
"--skip-grub-config",
Expand Down Expand Up @@ -512,28 +512,13 @@ def check_boot_flag(device):
if part is None:
raise HodorException("parted could not find partition")
if part.getFlag(parted.PARTITION_BOOT):
logging.debug("bootflag is enabled on %s" % device)
logging.debug("boot flag is enabled on %s" % device)
return
except HodorException as e:
logging.info("%s, falling back to old bootflag detection", e)
except ImportError:
logging.debug("could not import parted, falling back to old bootflag detection")

with open(boot_dev, "rb") as image:
data = image.read(520)
bootcode = data[440:]
gpt_data = bootcode[70:80]

if gpt_data == GPT_HEADER:
logging.info("GPT detected, skipping bootflag check")
elif bootcode[6] == b"\x80":
logging.debug("bootflag is enabled")
else:
logging.debug("bootflag is NOT enabled")
raise VerifyException(
"Device %s does not have the bootflag set. "
"Please enable it to be able to boot." % device
)
raise VerifyException(
"Could not import parted to verify boot flag on %s, please make sure python3-parted is installed."
% device
)


def mkfs_fat16(device):
Expand Down

0 comments on commit 5579b7b

Please sign in to comment.