diff --git a/src/modules/grub/main.py b/src/modules/grub/main.py index b5c6d9bad..1e8cb7a35 100644 --- a/src/modules/grub/main.py +++ b/src/modules/grub/main.py @@ -3,6 +3,8 @@ # === This file is part of Calamares - === # # Copyright 2014, Aurélien Gâteau +# Copyright 2014, Daniel Hillenbrand +# Copyright 2014, Kevin Kofler # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,13 +23,34 @@ import libcalamares from libcalamares.utils import check_chroot_call -def install_grub(boot_loader): - install_path = boot_loader["installPath"] - check_chroot_call([libcalamares.job.configuration["grubInstall"], install_path]) +def detect_firmware_type(): + # Check for EFI variables support + if(os.path.exists("/sys/firmware/efi/efivars")): + fw_type = 'efi' + else: + fw_type = 'bios' + + libcalamares.globalstorage.insert("firmwareType", fw_type) + libcalamares.utils.debug("Firmware type: {!s}".format(fw_type)) + + +def install_grub(boot_loader, fw_type): + if fw_type == 'efi': + efi_directory = "/boot/efi" + branding = libcalamares.globalstorage.value("branding") + distribution = branding["shortProductName"] + file_name_sanitizer = str.maketrans(" /", "_-") + check_chroot_call([libcalamares.job.configuration["grubInstall"], "--target=x86_64-efi", "--efi-directory={!s}".format(efi_directory), "--bootloader-id={!s}".format(distribution.translate(file_name_sanitizer))]) + else: + install_path = boot_loader["installPath"] + check_chroot_call([libcalamares.job.configuration["grubInstall"], install_path]) + check_chroot_call([libcalamares.job.configuration["grubMkconfig"], "-o", libcalamares.job.configuration["grubCfg"]]) def run(): + detect_firmware_type() boot_loader = libcalamares.globalstorage.value("bootLoader") - install_grub(boot_loader) + fw_type = libcalamares.globalstorage.value("firmwareType") + install_grub(boot_loader, fw_type) return None