Merge pull request #696 from siduction/fix-bootloader
WIP: fixes #692 bootloader module fails when /EFI/Boot exists
This commit is contained in:
commit
c1dacf93d9
@ -10,6 +10,7 @@
|
|||||||
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
|
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
|
||||||
# Copyright 2015, Philip Mueller <philm@manjaro.org>
|
# Copyright 2015, Philip Mueller <philm@manjaro.org>
|
||||||
# Copyright 2016-2017, Teo Mrnjavac <teo@kde.org>
|
# Copyright 2016-2017, Teo Mrnjavac <teo@kde.org>
|
||||||
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
||||||
#
|
#
|
||||||
# Calamares is free software: you can redistribute it and/or modify
|
# Calamares is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -25,6 +26,7 @@
|
|||||||
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import libcalamares
|
import libcalamares
|
||||||
@ -33,7 +35,8 @@ from libcalamares.utils import check_target_env_call
|
|||||||
|
|
||||||
|
|
||||||
def get_uuid():
|
def get_uuid():
|
||||||
""" Checks and passes 'uuid' to other routine.
|
"""
|
||||||
|
Checks and passes 'uuid' to other routine.
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
@ -51,7 +54,9 @@ def get_uuid():
|
|||||||
|
|
||||||
|
|
||||||
def get_bootloader_entry_name():
|
def get_bootloader_entry_name():
|
||||||
""" Passes 'bootloader_entry_name' to other routine based on configuration file.
|
"""
|
||||||
|
Passes 'bootloader_entry_name' to other routine based
|
||||||
|
on configuration file.
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
@ -63,7 +68,8 @@ def get_bootloader_entry_name():
|
|||||||
|
|
||||||
|
|
||||||
def get_kernel_line(kernel_type):
|
def get_kernel_line(kernel_type):
|
||||||
""" Passes 'kernel_line' to other routine based on configuration file.
|
"""
|
||||||
|
Passes 'kernel_line' to other routine based on configuration file.
|
||||||
|
|
||||||
:param kernel_type:
|
:param kernel_type:
|
||||||
:return:
|
:return:
|
||||||
@ -81,7 +87,8 @@ def get_kernel_line(kernel_type):
|
|||||||
|
|
||||||
|
|
||||||
def create_systemd_boot_conf(uuid, conf_path, kernel_line):
|
def create_systemd_boot_conf(uuid, conf_path, kernel_line):
|
||||||
""" Creates systemd-boot configuration files based on given parameters.
|
"""
|
||||||
|
Creates systemd-boot configuration files based on given parameters.
|
||||||
|
|
||||||
:param uuid:
|
:param uuid:
|
||||||
:param conf_path:
|
:param conf_path:
|
||||||
@ -102,11 +109,12 @@ def create_systemd_boot_conf(uuid, conf_path, kernel_line):
|
|||||||
swap_uuid = partition["uuid"]
|
swap_uuid = partition["uuid"]
|
||||||
|
|
||||||
if partition["mountPoint"] == "/" and "luksMapperName" in partition:
|
if partition["mountPoint"] == "/" and "luksMapperName" in partition:
|
||||||
cryptdevice_params = [
|
cryptdevice_params = ["cryptdevice=UUID="
|
||||||
"cryptdevice=UUID={!s}:{!s}".format(partition["luksUuid"],
|
+ partition["luksUuid"]
|
||||||
partition["luksMapperName"]),
|
+ ":"
|
||||||
"root=/dev/mapper/{!s}".format(partition["luksMapperName"])
|
+ partition["luksMapperName"],
|
||||||
]
|
"root=/dev/mapper/"
|
||||||
|
+ partition["luksMapperName"]]
|
||||||
|
|
||||||
if cryptdevice_params:
|
if cryptdevice_params:
|
||||||
kernel_params.extend(cryptdevice_params)
|
kernel_params.extend(cryptdevice_params)
|
||||||
@ -118,7 +126,8 @@ def create_systemd_boot_conf(uuid, conf_path, kernel_line):
|
|||||||
|
|
||||||
lines = [
|
lines = [
|
||||||
'## This is just an example config file.\n',
|
'## This is just an example config file.\n',
|
||||||
'## Please edit the paths and kernel parameters according to your system.\n',
|
'## Please edit the paths and kernel parameters according\n',
|
||||||
|
'## to your system.\n',
|
||||||
'\n',
|
'\n',
|
||||||
"title {!s}{!s}\n".format(distribution, kernel_line),
|
"title {!s}{!s}\n".format(distribution, kernel_line),
|
||||||
"linux {!s}\n".format(kernel),
|
"linux {!s}\n".format(kernel),
|
||||||
@ -132,7 +141,8 @@ def create_systemd_boot_conf(uuid, conf_path, kernel_line):
|
|||||||
|
|
||||||
|
|
||||||
def create_loader(loader_path):
|
def create_loader(loader_path):
|
||||||
""" Writes configuration for loader.
|
"""
|
||||||
|
Writes configuration for loader.
|
||||||
|
|
||||||
:param loader_path:
|
:param loader_path:
|
||||||
"""
|
"""
|
||||||
@ -151,7 +161,8 @@ def create_loader(loader_path):
|
|||||||
|
|
||||||
|
|
||||||
def install_systemd_boot(efi_directory):
|
def install_systemd_boot(efi_directory):
|
||||||
""" Installs systemd-boot as bootloader for EFI setups.
|
"""
|
||||||
|
Installs systemd-boot as bootloader for EFI setups.
|
||||||
|
|
||||||
:param efi_directory:
|
:param efi_directory:
|
||||||
"""
|
"""
|
||||||
@ -165,11 +176,11 @@ def install_systemd_boot(efi_directory):
|
|||||||
conf_path = os.path.join(install_efi_directory,
|
conf_path = os.path.join(install_efi_directory,
|
||||||
"loader",
|
"loader",
|
||||||
"entries",
|
"entries",
|
||||||
"{!s}.conf".format(distribution_translated))
|
distribution_translated +".conf")
|
||||||
fallback_path = os.path.join(install_efi_directory,
|
fallback_path = os.path.join(install_efi_directory,
|
||||||
"loader",
|
"loader",
|
||||||
"entries",
|
"entries",
|
||||||
"{!s}-fallback.conf".format(distribution_translated))
|
distribution_translated + "-fallback.conf")
|
||||||
loader_path = os.path.join(install_efi_directory,
|
loader_path = os.path.join(install_efi_directory,
|
||||||
"loader",
|
"loader",
|
||||||
"loader.conf")
|
"loader.conf")
|
||||||
@ -186,19 +197,23 @@ def install_systemd_boot(efi_directory):
|
|||||||
|
|
||||||
|
|
||||||
def install_grub(efi_directory, fw_type):
|
def install_grub(efi_directory, fw_type):
|
||||||
""" Installs grub as bootloader, either in pc or efi mode.
|
"""
|
||||||
|
Installs grub as bootloader, either in pc or efi mode.
|
||||||
|
|
||||||
:param efi_directory:
|
:param efi_directory:
|
||||||
:param fw_type:
|
:param fw_type:
|
||||||
"""
|
"""
|
||||||
if fw_type == "efi":
|
if fw_type == "efi":
|
||||||
print("Bootloader: grub (efi)")
|
print("Bootloader: grub (efi)")
|
||||||
|
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
||||||
|
install_efi_directory = install_path + efi_directory
|
||||||
|
|
||||||
if not os.path.isdir(efi_directory):
|
if not os.path.isdir(install_efi_directory):
|
||||||
check_target_env_call(["mkdir", "-p", "{!s}".format(efi_directory)])
|
os.makedirs(install_efi_directory)
|
||||||
|
|
||||||
if "efiBootloaderId" in libcalamares.job.configuration:
|
if "efiBootloaderId" in libcalamares.job.configuration:
|
||||||
efi_bootloader_id = libcalamares.job.configuration["efiBootloaderId"]
|
efi_bootloader_id = libcalamares.job.configuration[
|
||||||
|
"efiBootloaderId"]
|
||||||
else:
|
else:
|
||||||
branding = libcalamares.globalstorage.value("branding")
|
branding = libcalamares.globalstorage.value("branding")
|
||||||
distribution = branding["bootloaderEntryName"]
|
distribution = branding["bootloaderEntryName"]
|
||||||
@ -212,32 +227,38 @@ def install_grub(efi_directory, fw_type):
|
|||||||
# if the kernel is older than 4.0, the UEFI bitness likely isn't
|
# if the kernel is older than 4.0, the UEFI bitness likely isn't
|
||||||
# exposed to the userspace so we assume a 64 bit UEFI here
|
# exposed to the userspace so we assume a 64 bit UEFI here
|
||||||
efi_bitness = "64"
|
efi_bitness = "64"
|
||||||
bitness_translate = {"32": "--target=i386-efi", "64": "--target=x86_64-efi"}
|
bitness_translate = {"32": "--target=i386-efi",
|
||||||
|
"64": "--target=x86_64-efi"}
|
||||||
check_target_env_call([libcalamares.job.configuration["grubInstall"],
|
check_target_env_call([libcalamares.job.configuration["grubInstall"],
|
||||||
bitness_translate[efi_bitness],
|
bitness_translate[efi_bitness],
|
||||||
"--efi-directory={!s}".format(efi_directory),
|
"--efi-directory=" + efi_directory,
|
||||||
"--bootloader-id={!s}".format(efi_bootloader_id),
|
"--bootloader-id=" + efi_bootloader_id,
|
||||||
"--force"])
|
"--force"])
|
||||||
|
|
||||||
# VFAT is weird, see issue CAL-385
|
# VFAT is weird, see issue CAL-385
|
||||||
efi_directory_firmware = os.path.join(efi_directory, "EFI")
|
install_efi_directory_firmware = (vfat_correct_case(
|
||||||
if os.path.exists(efi_directory_firmware):
|
install_efi_directory,
|
||||||
efi_directory_firmware = vfat_correct_case(efi_directory, "EFI")
|
"EFI"))
|
||||||
|
if not os.path.exists(install_efi_directory_firmware):
|
||||||
|
os.makedirs(install_efi_directory_firmware)
|
||||||
|
|
||||||
efi_boot_directory = os.path.join(efi_directory_firmware, "boot")
|
# there might be several values for the boot directory
|
||||||
if os.path.exists(efi_boot_directory):
|
# most usual they are boot, Boot, BOOT
|
||||||
efi_boot_directory = vfat_correct_case(efi_directory_firmware, "boot")
|
|
||||||
else:
|
install_efi_boot_directory = (vfat_correct_case(
|
||||||
check_target_env_call(["mkdir", "-p", efi_boot_directory])
|
install_efi_directory_firmware,
|
||||||
|
"boot"))
|
||||||
|
if not os.path.exists(install_efi_boot_directory):
|
||||||
|
os.makedirs(install_efi_boot_directory)
|
||||||
|
|
||||||
# Workaround for some UEFI firmwares
|
# Workaround for some UEFI firmwares
|
||||||
efi_file_source = {"32": os.path.join(efi_directory_firmware, efi_bootloader_id, "grubia32.efi"),
|
efi_file_source = {"32": os.path.join(install_efi_directory_firmware,
|
||||||
"64": os.path.join(efi_directory_firmware, efi_bootloader_id, "grubx64.efi")}
|
efi_bootloader_id,
|
||||||
efi_file_target = {"32": os.path.join(efi_boot_directory, "bootia32.efi"),
|
"grubia32.efi"),
|
||||||
"64": os.path.join(efi_boot_directory, "bootx64.efi")}
|
"64": os.path.join(install_efi_directory_firmware,
|
||||||
check_target_env_call(["cp",
|
efi_bootloader_id,
|
||||||
efi_file_source[efi_bitness],
|
"grubx64.efi")}
|
||||||
efi_file_target[efi_bitness]])
|
shutil.copy2(efi_file_source[efi_bitness], install_efi_boot_directory)
|
||||||
else:
|
else:
|
||||||
print("Bootloader: grub (bios)")
|
print("Bootloader: grub (bios)")
|
||||||
if libcalamares.globalstorage.value("bootLoader") is None:
|
if libcalamares.globalstorage.value("bootLoader") is None:
|
||||||
@ -256,8 +277,7 @@ def install_grub(efi_directory, fw_type):
|
|||||||
# The file specified in grubCfg should already be filled out
|
# The file specified in grubCfg should already be filled out
|
||||||
# by the grubcfg job module.
|
# by the grubcfg job module.
|
||||||
check_target_env_call([libcalamares.job.configuration["grubMkconfig"],
|
check_target_env_call([libcalamares.job.configuration["grubMkconfig"],
|
||||||
"-o",
|
"-o", libcalamares.job.configuration["grubCfg"]])
|
||||||
libcalamares.job.configuration["grubCfg"]])
|
|
||||||
|
|
||||||
|
|
||||||
def vfat_correct_case(parent, name):
|
def vfat_correct_case(parent, name):
|
||||||
@ -268,8 +288,10 @@ def vfat_correct_case(parent, name):
|
|||||||
|
|
||||||
|
|
||||||
def prepare_bootloader(fw_type):
|
def prepare_bootloader(fw_type):
|
||||||
""" Prepares bootloader.
|
"""
|
||||||
Based on value 'efi_boot_loader', it either calls systemd-boot or grub to be installed.
|
Prepares bootloader.
|
||||||
|
Based on value 'efi_boot_loader', it either calls systemd-boot
|
||||||
|
or grub to be installed.
|
||||||
|
|
||||||
:param fw_type:
|
:param fw_type:
|
||||||
:return:
|
:return:
|
||||||
@ -284,14 +306,16 @@ def prepare_bootloader(fw_type):
|
|||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
""" Starts procedure and passes 'fw_type' to other routine.
|
"""
|
||||||
|
Starts procedure and passes 'fw_type' to other routine.
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fw_type = libcalamares.globalstorage.value("firmwareType")
|
fw_type = libcalamares.globalstorage.value("firmwareType")
|
||||||
|
|
||||||
if libcalamares.globalstorage.value("bootLoader") is None and fw_type != "efi":
|
if (libcalamares.globalstorage.value("bootLoader") is None
|
||||||
|
and fw_type != "efi"):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
partitions = libcalamares.globalstorage.value("partitions")
|
partitions = libcalamares.globalstorage.value("partitions")
|
||||||
@ -300,7 +324,8 @@ def run():
|
|||||||
esp_found = False
|
esp_found = False
|
||||||
|
|
||||||
for partition in partitions:
|
for partition in partitions:
|
||||||
if partition["mountPoint"] == libcalamares.globalstorage.value("efiSystemPartition"):
|
if (partition["mountPoint"] ==
|
||||||
|
libcalamares.globalstorage.value("efiSystemPartition")):
|
||||||
esp_found = True
|
esp_found = True
|
||||||
|
|
||||||
if not esp_found:
|
if not esp_found:
|
||||||
|
Loading…
Reference in New Issue
Block a user