Merge pull request #1080 from a-wai/fix-systemd-boot-install

[bootloader] Fix systemd-boot installation
This commit is contained in:
Adriaan de Groot 2019-02-11 08:49:22 -05:00 committed by GitHub
commit 7711cb0ad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -87,17 +87,18 @@ def get_kernel_line(kernel_type):
return ""
def create_systemd_boot_conf(uuid, conf_path, kernel_line):
def create_systemd_boot_conf(install_path, efi_dir, uuid, entry, entry_name, kernel_type):
"""
Creates systemd-boot configuration files based on given parameters.
:param install_path:
:param efi_dir:
:param uuid:
:param conf_path:
:param kernel_line:
:param entry:
:param entry_name:
:param kernel_type:
"""
distribution = get_bootloader_entry_name()
kernel = libcalamares.job.configuration["kernel"]
img = libcalamares.job.configuration["img"]
kernel_params = ["quiet"]
partitions = libcalamares.globalstorage.value("partitions")
@ -131,14 +132,40 @@ def create_systemd_boot_conf(uuid, conf_path, kernel_line):
if swap_uuid:
kernel_params.append("resume=UUID={!s}".format(swap_uuid))
kernel_line = get_kernel_line(kernel_type)
libcalamares.utils.debug("Configure: \"{!s}\"".format(kernel_line))
if kernel_type == "fallback":
img = libcalamares.job.configuration["fallback"]
entry_name = entry_name + "-fallback"
else:
img = libcalamares.job.configuration["img"]
conf_path = os.path.join(install_path + efi_dir,
"loader",
"entries",
entry_name + ".conf")
# Copy kernel and initramfs to a subdirectory of /efi partition
files_dir = os.path.join(install_path + efi_dir, entry_name)
os.mkdir(files_dir)
kernel_path = install_path + kernel
kernel_name = os.path.basename(kernel_path)
shutil.copyfile(kernel_path, os.path.join(files_dir, kernel_name))
img_path = install_path + img
img_name = os.path.basename(img_path)
shutil.copyfile(img_path, os.path.join(files_dir, img_name))
lines = [
'## This is just an example config file.\n',
'## Please edit the paths and kernel parameters according\n',
'## to your system.\n',
'\n',
"title {!s}{!s}\n".format(distribution, kernel_line),
"linux {!s}\n".format(kernel),
"initrd {!s}\n".format(img),
"title {!s}{!s}\n".format(entry, kernel_line),
"linux {!s}\n".format(os.path.join("/", entry_name, kernel_name)),
"initrd {!s}\n".format(os.path.join("/", entry_name, img_name)),
"options {!s} rw\n".format(" ".join(kernel_params)),
]
@ -147,19 +174,17 @@ def create_systemd_boot_conf(uuid, conf_path, kernel_line):
conf_file.write(line)
def create_loader(loader_path):
def create_loader(loader_path, entry):
"""
Writes configuration for loader.
:param loader_path:
:param entry:
"""
distribution = get_bootloader_entry_name()
timeout = libcalamares.job.configuration["timeout"]
file_name_sanitizer = str.maketrans(" /", "_-")
distribution_translated = distribution.translate(file_name_sanitizer)
lines = [
"timeout {!s}\n".format(timeout),
"default {!s}\n".format(distribution_translated),
"default {!s}\n".format(entry),
]
with open(loader_path, 'w') as loader_file:
@ -204,27 +229,26 @@ def install_systemd_boot(efi_directory):
distribution = get_bootloader_entry_name()
file_name_sanitizer = str.maketrans(" /", "_-")
distribution_translated = distribution.translate(file_name_sanitizer)
conf_path = os.path.join(install_efi_directory,
"loader",
"entries",
distribution_translated + ".conf")
fallback_path = os.path.join(install_efi_directory,
"loader",
"entries",
distribution_translated + "-fallback.conf")
loader_path = os.path.join(install_efi_directory,
"loader",
"loader.conf")
subprocess.call(["bootctl",
"--path={!s}".format(install_efi_directory),
"install"])
kernel_line = get_kernel_line("default")
libcalamares.utils.debug("Configure: \"{!s}\"".format(kernel_line))
create_systemd_boot_conf(uuid, conf_path, kernel_line)
kernel_line = get_kernel_line("fallback")
libcalamares.utils.debug("Configure: \"{!s}\"".format(kernel_line))
create_systemd_boot_conf(uuid, fallback_path, kernel_line)
create_loader(loader_path)
create_systemd_boot_conf(install_path,
efi_directory,
uuid,
distribution,
distribution_translated,
"default")
if "fallback" in libcalamares.job.configuration:
create_systemd_boot_conf(install_path,
efi_directory,
uuid,
distribution,
distribution_translated,
"fallback")
create_loader(loader_path, distribution_translated)
def install_grub(efi_directory, fw_type):