linux = opts.linux
combined_sigs = '{}'
- if opts.linux and sign_args_present:
+ # On some distros, on some architectures, the vmlinuz is a gzip file, so we need to decompress it
+ # if it's not a valid PE file, as it will fail to be booted by the firmware.
+ if linux:
+ try:
+ pefile.PE(linux, fast_load=True)
+ except pefile.PEFormatError:
+ try:
+ decompressed = maybe_decompress(linux)
+ except NotImplementedError:
+ print(f'{linux} is not a valid PE file and cannot be decompressed either', file=sys.stderr)
+ else:
+ print(f'{linux} is compressed and cannot be loaded by UEFI, decompressing', file=sys.stderr)
+ linux = Path(tempfile.NamedTemporaryFile(prefix='linux-decompressed').name)
+ linux.write_bytes(decompressed)
+
+ if linux and sign_args_present:
assert opts.signtool is not None
signtool = SignTool.from_string(opts.signtool)
if sign_kernel:
linux_signed = tempfile.NamedTemporaryFile(prefix='linux-signed')
+ signtool.sign(os.fspath(linux), os.fspath(Path(linux_signed.name)), opts=opts)
linux = Path(linux_signed.name)
- signtool.sign(os.fspath(opts.linux), os.fspath(linux), opts=opts)
- if opts.uname is None and opts.linux is not None:
+ if opts.uname is None and linux is not None:
print('Kernel version not specified, starting autodetection 😖.', file=sys.stderr)
- opts.uname = Uname.scrape(opts.linux, opts=opts)
+ opts.uname = Uname.scrape(linux, opts=opts)
uki = UKI(opts.join_pcrsig if opts.join_pcrsig else opts.stub)
initrd = join_initrds(opts.initrd)