check_boot_flag(): Open device in binary mode
authorSven Joachim <svenjoac@gmx.de>
Wed, 30 Oct 2019 16:35:03 +0000 (17:35 +0100)
committerSven Joachim <svenjoac@gmx.de>
Wed, 30 Oct 2019 16:35:03 +0000 (17:35 +0100)
By default open() reads in text which is not going to fly for a boot
sector.

Fatal: 'utf-8' codec can't decode byte 0x90 in position 6: invalid start byte
Exception:
Traceback (most recent call last):
  File "/usr/sbin/grml2usb", line 1913, in main
    install(iso, device)
  File "/usr/sbin/grml2usb", line 1626, in install
    install_grml(iso_mountpoint, device)
  File "/usr/sbin/grml2usb", line 1653, in install_grml
    check_boot_flag(device)
  File "/usr/sbin/grml2usb", line 393, in check_boot_flag
    data = image.read(520)
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 6: invalid start byte

grml2usb

index eaeba08..75fcd3e 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -389,7 +389,7 @@ def check_boot_flag(device):
     except ImportError as e:
         logging.debug("could not import parted, falling back to old bootflag detection")
 
-    with open(boot_dev, 'r') as image:
+    with open(boot_dev, 'rb') as image:
         data = image.read(520)
         bootcode = data[440:]
         gpt_data = bootcode[70:80]