The approach to check the 7th field in the MBR for the
bootable flag being set isn't enough. This fails to detect
bootable partitions if they aren't the first primary ones.
pyparted provides a way to check whether the specified
partition really has the boot flag set, so let's use this
approach, iff pyparted is available.
Took the get_partition_for_path function from Evgeni Golov's
https://github.com/evgeni/grml2usb/tree/pyparted with his
permission.
Package: grml2usb
Architecture: i386 amd64
Package: grml2usb
Architecture: i386 amd64
-Depends: ${shlibs:Depends}, ${misc:Depends}, syslinux | grub-pc, python, rsync, mtools, realpath
+Depends: ${shlibs:Depends}, ${misc:Depends}, syslinux | grub-pc, python, python-parted, rsync, mtools, realpath
Recommends: syslinux, isolinux, xorriso | genisoimage
Description: install Grml system / ISO to usb device
This script installs a Grml ISO to an USB device to be able
Recommends: syslinux, isolinux, xorriso | genisoimage
Description: install Grml system / ISO to usb device
This script installs a Grml ISO to an USB device to be able
raise CriticalException("please run this script with uid 0 (root).")
raise CriticalException("please run this script with uid 0 (root).")
+# for usage inside check_boot_flag
+def get_partition_for_path(path):
+ import parted
+
+ boot_dev, x = get_device_from_partition(path)
+
+ d = parted.getDevice(boot_dev)
+ disk = parted.Disk(d)
+ return disk.getPartitionByPath(path)
+
+
def check_boot_flag(device):
boot_dev, x = get_device_from_partition(device)
def check_boot_flag(device):
boot_dev, x = get_device_from_partition(device)
+ try:
+ import parted
+ part = get_partition_for_path(device)
+ if part.getFlag(parted.PARTITION_BOOT):
+ logging.debug("bootflag is enabled on %s" % device)
+ return
+ except ImportError, e:
+ pass
+
with open(boot_dev, 'r') as image:
data = image.read(520)
bootcode = data[440:]
with open(boot_dev, 'r') as image:
data = image.read(520)
bootcode = data[440:]
else:
logging.debug("bootflag is NOT enabled")
raise VerifyException("Device %s does not have the bootflag set. "
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." % boot_dev)
+ "Please enable it to be able to boot." % device)