2014-10-12 19:45:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-02-18 15:06:10 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-12-20 14:39:09 +01:00
|
|
|
# === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-10-12 19:45:02 +02:00
|
|
|
#
|
|
|
|
# Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
|
|
|
# Copyright 2014, Anke Boersma <demm@kaosx.us>
|
|
|
|
# Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org>
|
|
|
|
# Copyright 2014, Benjamin Vaudour <benjamin.vaudour@yahoo.fr>
|
2015-02-20 00:28:44 +01:00
|
|
|
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
|
2018-06-17 07:47:58 +02:00
|
|
|
# Copyright 2015-2018, Philip Mueller <philm@manjaro.org>
|
2017-02-17 16:20:43 +01:00
|
|
|
# Copyright 2016-2017, Teo Mrnjavac <teo@kde.org>
|
2017-03-16 16:59:28 +01:00
|
|
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
2018-01-30 11:22:36 +01:00
|
|
|
# Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
2017-09-07 09:42:46 +02:00
|
|
|
# Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org>
|
2017-10-25 19:47:23 +02:00
|
|
|
# Copyright 2017, Ben Green <Bezzy1999@hotmail.com>
|
2014-10-12 19:45:02 +02:00
|
|
|
#
|
|
|
|
# Calamares is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Calamares is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
2017-03-16 16:59:28 +01:00
|
|
|
import shutil
|
2014-10-12 19:45:02 +02:00
|
|
|
import subprocess
|
|
|
|
|
2016-08-23 10:20:52 +02:00
|
|
|
import libcalamares
|
|
|
|
|
2015-08-06 12:13:21 +02:00
|
|
|
from libcalamares.utils import check_target_env_call
|
2014-10-12 19:45:02 +02:00
|
|
|
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
def get_uuid():
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Checks and passes 'uuid' to other routine.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2014-10-12 19:45:02 +02:00
|
|
|
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
2015-06-14 05:08:52 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
for partition in partitions:
|
|
|
|
if partition["mountPoint"] == "/":
|
2018-01-30 11:26:29 +01:00
|
|
|
libcalamares.utils.debug("Root partition uuid: \"{!s}\"".format(partition["uuid"]))
|
2014-10-12 19:45:02 +02:00
|
|
|
return partition["uuid"]
|
2015-06-14 05:08:52 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
return ""
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2014-11-19 17:01:02 +01:00
|
|
|
def get_bootloader_entry_name():
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Passes 'bootloader_entry_name' to other routine based
|
|
|
|
on configuration file.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2015-02-19 17:59:52 +01:00
|
|
|
if "bootloaderEntryName" in libcalamares.job.configuration:
|
|
|
|
return libcalamares.job.configuration["bootloaderEntryName"]
|
2014-11-19 17:01:02 +01:00
|
|
|
else:
|
|
|
|
branding = libcalamares.globalstorage.value("branding")
|
2015-02-19 17:59:52 +01:00
|
|
|
return branding["bootloaderEntryName"]
|
2015-02-19 17:39:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_kernel_line(kernel_type):
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Passes 'kernel_line' to other routine based on configuration file.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param kernel_type:
|
|
|
|
:return:
|
|
|
|
"""
|
2015-02-19 18:10:31 +01:00
|
|
|
if kernel_type == "fallback":
|
|
|
|
if "fallbackKernelLine" in libcalamares.job.configuration:
|
2015-02-19 17:39:11 +01:00
|
|
|
return libcalamares.job.configuration["fallbackKernelLine"]
|
|
|
|
else:
|
|
|
|
return " (fallback)"
|
2015-02-19 18:10:31 +01:00
|
|
|
else:
|
|
|
|
if "kernelLine" in libcalamares.job.configuration:
|
|
|
|
return libcalamares.job.configuration["kernelLine"]
|
2015-02-19 17:39:11 +01:00
|
|
|
else:
|
|
|
|
return ""
|
2014-11-19 17:01:02 +01:00
|
|
|
|
2015-02-18 16:03:57 +01:00
|
|
|
|
2019-02-08 18:00:58 +01:00
|
|
|
def create_systemd_boot_conf(install_path, efi_dir, uuid, entry, entry_name, kernel_type):
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Creates systemd-boot configuration files based on given parameters.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
2019-02-08 18:00:58 +01:00
|
|
|
:param install_path:
|
|
|
|
:param efi_dir:
|
2015-02-20 20:54:25 +01:00
|
|
|
:param uuid:
|
2019-02-08 18:00:58 +01:00
|
|
|
:param entry:
|
|
|
|
:param entry_name:
|
|
|
|
:param kernel_type:
|
2015-02-20 20:54:25 +01:00
|
|
|
"""
|
2014-11-11 06:13:15 +01:00
|
|
|
kernel = libcalamares.job.configuration["kernel"]
|
2016-05-04 13:05:04 +02:00
|
|
|
kernel_params = ["quiet"]
|
|
|
|
|
2014-11-11 06:13:15 +01:00
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
2016-05-04 13:05:04 +02:00
|
|
|
swap_uuid = ""
|
|
|
|
|
|
|
|
cryptdevice_params = []
|
2015-06-14 05:08:52 +02:00
|
|
|
|
2017-09-07 09:42:46 +02:00
|
|
|
# Take over swap settings:
|
|
|
|
# - unencrypted swap partition sets swap_uuid
|
|
|
|
# - encrypted root sets cryptdevice_params
|
2014-11-11 06:13:15 +01:00
|
|
|
for partition in partitions:
|
2017-09-07 09:42:46 +02:00
|
|
|
has_luks = "luksMapperName" in partition
|
|
|
|
if partition["fs"] == "linuxswap" and not has_luks:
|
2016-05-04 13:05:04 +02:00
|
|
|
swap_uuid = partition["uuid"]
|
|
|
|
|
2017-09-07 09:42:46 +02:00
|
|
|
if partition["mountPoint"] == "/" and has_luks:
|
2017-03-24 16:39:25 +01:00
|
|
|
cryptdevice_params = ["cryptdevice=UUID="
|
|
|
|
+ partition["luksUuid"]
|
|
|
|
+ ":"
|
|
|
|
+ partition["luksMapperName"],
|
|
|
|
"root=/dev/mapper/"
|
2017-09-07 09:42:46 +02:00
|
|
|
+ partition["luksMapperName"],
|
|
|
|
"resume=/dev/mapper/"
|
2017-03-24 16:39:25 +01:00
|
|
|
+ partition["luksMapperName"]]
|
2016-05-04 13:05:04 +02:00
|
|
|
|
|
|
|
if cryptdevice_params:
|
|
|
|
kernel_params.extend(cryptdevice_params)
|
|
|
|
else:
|
|
|
|
kernel_params.append("root=UUID={!s}".format(uuid))
|
|
|
|
|
|
|
|
if swap_uuid:
|
|
|
|
kernel_params.append("resume=UUID={!s}".format(swap_uuid))
|
2015-02-15 00:03:50 +01:00
|
|
|
|
2019-02-08 18:00:58 +01:00
|
|
|
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))
|
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
lines = [
|
2015-02-19 20:24:07 +01:00
|
|
|
'## This is just an example config file.\n',
|
2017-03-16 16:59:28 +01:00
|
|
|
'## Please edit the paths and kernel parameters according\n',
|
|
|
|
'## to your system.\n',
|
2014-10-12 19:45:02 +02:00
|
|
|
'\n',
|
2019-02-08 18:00:58 +01:00
|
|
|
"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)),
|
2016-05-04 13:05:04 +02:00
|
|
|
"options {!s} rw\n".format(" ".join(kernel_params)),
|
2014-10-12 19:45:02 +02:00
|
|
|
]
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2016-05-04 13:30:54 +02:00
|
|
|
with open(conf_path, 'w') as conf_file:
|
|
|
|
for line in lines:
|
|
|
|
conf_file.write(line)
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2019-02-08 18:00:58 +01:00
|
|
|
def create_loader(loader_path, entry):
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Writes configuration for loader.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param loader_path:
|
2019-02-08 18:00:58 +01:00
|
|
|
:param entry:
|
2015-02-20 20:54:25 +01:00
|
|
|
"""
|
2014-10-12 19:45:02 +02:00
|
|
|
timeout = libcalamares.job.configuration["timeout"]
|
|
|
|
lines = [
|
2015-02-17 13:53:51 +01:00
|
|
|
"timeout {!s}\n".format(timeout),
|
2019-02-08 18:00:58 +01:00
|
|
|
"default {!s}\n".format(entry),
|
2014-10-12 19:45:02 +02:00
|
|
|
]
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2016-05-04 13:30:54 +02:00
|
|
|
with open(loader_path, 'w') as loader_file:
|
|
|
|
for line in lines:
|
|
|
|
loader_file.write(line)
|
2014-10-16 21:08:18 +02:00
|
|
|
|
|
|
|
|
2018-02-20 16:47:14 +01:00
|
|
|
def efi_label():
|
|
|
|
if "efiBootloaderId" in libcalamares.job.configuration:
|
|
|
|
efi_bootloader_id = libcalamares.job.configuration[
|
|
|
|
"efiBootloaderId"]
|
|
|
|
else:
|
|
|
|
branding = libcalamares.globalstorage.value("branding")
|
|
|
|
efi_bootloader_id = branding["bootloaderEntryName"]
|
|
|
|
|
|
|
|
file_name_sanitizer = str.maketrans(" /", "_-")
|
|
|
|
return efi_bootloader_id.translate(file_name_sanitizer)
|
|
|
|
|
|
|
|
|
2018-05-28 15:24:43 +02:00
|
|
|
def efi_word_size():
|
|
|
|
# get bitness of the underlying UEFI
|
|
|
|
try:
|
|
|
|
sysfile = open("/sys/firmware/efi/fw_platform_size", "r")
|
|
|
|
efi_bitness = sysfile.read(2)
|
|
|
|
except Exception:
|
|
|
|
# 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
|
|
|
|
efi_bitness = "64"
|
|
|
|
return efi_bitness
|
|
|
|
|
|
|
|
|
2015-06-11 00:32:34 +02:00
|
|
|
def install_systemd_boot(efi_directory):
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Installs systemd-boot as bootloader for EFI setups.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param efi_directory:
|
|
|
|
"""
|
2018-01-30 11:26:29 +01:00
|
|
|
libcalamares.utils.debug("Bootloader: systemd-boot")
|
2015-02-20 00:28:44 +01:00
|
|
|
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
|
|
|
install_efi_directory = install_path + efi_directory
|
|
|
|
uuid = get_uuid()
|
|
|
|
distribution = get_bootloader_entry_name()
|
|
|
|
file_name_sanitizer = str.maketrans(" /", "_-")
|
|
|
|
distribution_translated = distribution.translate(file_name_sanitizer)
|
2016-05-04 13:30:54 +02:00
|
|
|
loader_path = os.path.join(install_efi_directory,
|
|
|
|
"loader",
|
|
|
|
"loader.conf")
|
|
|
|
subprocess.call(["bootctl",
|
|
|
|
"--path={!s}".format(install_efi_directory),
|
|
|
|
"install"])
|
2019-02-08 18:00:58 +01:00
|
|
|
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)
|
2015-02-20 00:28:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def install_grub(efi_directory, fw_type):
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Installs grub as bootloader, either in pc or efi mode.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param efi_directory:
|
|
|
|
:param fw_type:
|
|
|
|
"""
|
2015-02-20 00:28:44 +01:00
|
|
|
if fw_type == "efi":
|
2018-01-30 11:26:29 +01:00
|
|
|
libcalamares.utils.debug("Bootloader: grub (efi)")
|
2017-03-16 16:59:28 +01:00
|
|
|
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
|
|
|
install_efi_directory = install_path + efi_directory
|
2016-08-23 10:20:52 +02:00
|
|
|
|
2017-03-16 16:59:28 +01:00
|
|
|
if not os.path.isdir(install_efi_directory):
|
2017-03-24 16:39:25 +01:00
|
|
|
os.makedirs(install_efi_directory)
|
2015-06-14 05:08:52 +02:00
|
|
|
|
2018-02-20 16:47:14 +01:00
|
|
|
efi_bootloader_id = efi_label()
|
2018-05-28 15:24:43 +02:00
|
|
|
efi_bitness = efi_word_size()
|
2017-10-24 21:32:15 +02:00
|
|
|
|
|
|
|
if efi_bitness == "32":
|
|
|
|
efi_target = "i386-efi"
|
|
|
|
efi_grub_file = "grubia32.efi"
|
|
|
|
efi_boot_file = "bootia32.efi"
|
|
|
|
elif efi_bitness == "64":
|
|
|
|
efi_target = "x86_64-efi"
|
|
|
|
efi_grub_file = "grubx64.efi"
|
|
|
|
efi_boot_file = "bootx64.efi"
|
|
|
|
|
2016-05-04 13:30:54 +02:00
|
|
|
check_target_env_call([libcalamares.job.configuration["grubInstall"],
|
2017-10-24 21:32:15 +02:00
|
|
|
"--target=" + efi_target,
|
2017-03-24 16:39:25 +01:00
|
|
|
"--efi-directory=" + efi_directory,
|
|
|
|
"--bootloader-id=" + efi_bootloader_id,
|
2016-05-04 13:30:54 +02:00
|
|
|
"--force"])
|
2016-08-23 10:20:52 +02:00
|
|
|
|
|
|
|
# VFAT is weird, see issue CAL-385
|
2017-03-24 16:39:25 +01:00
|
|
|
install_efi_directory_firmware = (vfat_correct_case(
|
|
|
|
install_efi_directory,
|
|
|
|
"EFI"))
|
2017-03-16 16:59:28 +01:00
|
|
|
if not os.path.exists(install_efi_directory_firmware):
|
2017-03-24 16:39:25 +01:00
|
|
|
os.makedirs(install_efi_directory_firmware)
|
2016-09-16 16:30:17 +02:00
|
|
|
|
2017-03-16 16:59:28 +01:00
|
|
|
# there might be several values for the boot directory
|
|
|
|
# most usual they are boot, Boot, BOOT
|
|
|
|
|
2017-03-24 16:39:25 +01:00
|
|
|
install_efi_boot_directory = (vfat_correct_case(
|
|
|
|
install_efi_directory_firmware,
|
|
|
|
"boot"))
|
2017-03-16 16:59:28 +01:00
|
|
|
if not os.path.exists(install_efi_boot_directory):
|
2017-03-24 16:39:25 +01:00
|
|
|
os.makedirs(install_efi_boot_directory)
|
2016-08-23 10:20:52 +02:00
|
|
|
|
2015-02-20 00:28:44 +01:00
|
|
|
# Workaround for some UEFI firmwares
|
2018-01-30 11:22:36 +01:00
|
|
|
FALLBACK = "installEFIFallback"
|
|
|
|
libcalamares.utils.debug("UEFI Fallback: " + str(libcalamares.job.configuration.get(FALLBACK, "<unset>")))
|
|
|
|
if libcalamares.job.configuration.get(FALLBACK, True):
|
|
|
|
libcalamares.utils.debug(" .. installing '{!s}' fallback firmware".format(efi_boot_file))
|
2018-01-29 22:55:07 +01:00
|
|
|
efi_file_source = os.path.join(install_efi_directory_firmware,
|
|
|
|
efi_bootloader_id,
|
|
|
|
efi_grub_file)
|
|
|
|
efi_file_target = os.path.join(install_efi_boot_directory,
|
|
|
|
efi_boot_file)
|
|
|
|
|
|
|
|
shutil.copy2(efi_file_source, efi_file_target)
|
2015-02-20 00:28:44 +01:00
|
|
|
else:
|
2018-01-30 11:26:29 +01:00
|
|
|
libcalamares.utils.debug("Bootloader: grub (bios)")
|
2017-01-18 19:10:09 +01:00
|
|
|
if libcalamares.globalstorage.value("bootLoader") is None:
|
|
|
|
return
|
|
|
|
|
2015-02-20 00:28:44 +01:00
|
|
|
boot_loader = libcalamares.globalstorage.value("bootLoader")
|
2017-01-18 19:10:09 +01:00
|
|
|
if boot_loader["installPath"] is None:
|
|
|
|
return
|
|
|
|
|
2016-05-04 13:30:54 +02:00
|
|
|
check_target_env_call([libcalamares.job.configuration["grubInstall"],
|
|
|
|
"--target=i386-pc",
|
|
|
|
"--recheck",
|
|
|
|
"--force",
|
|
|
|
boot_loader["installPath"]])
|
|
|
|
|
2016-05-04 13:35:40 +02:00
|
|
|
# The file specified in grubCfg should already be filled out
|
|
|
|
# by the grubcfg job module.
|
2016-05-04 13:30:54 +02:00
|
|
|
check_target_env_call([libcalamares.job.configuration["grubMkconfig"],
|
2017-03-24 16:39:25 +01:00
|
|
|
"-o", libcalamares.job.configuration["grubCfg"]])
|
2015-02-20 00:28:44 +01:00
|
|
|
|
|
|
|
|
2018-02-20 10:22:35 +01:00
|
|
|
def install_secureboot(efi_directory):
|
|
|
|
"""
|
|
|
|
Installs the secureboot shim in the system by calling efibootmgr.
|
|
|
|
"""
|
2018-02-20 16:47:14 +01:00
|
|
|
efi_bootloader_id = efi_label()
|
2018-05-28 15:26:20 +02:00
|
|
|
|
|
|
|
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
|
|
|
install_efi_directory = install_path + efi_directory
|
|
|
|
|
|
|
|
if efi_word_size() == "64":
|
|
|
|
install_efi_bin = "shim64.efi"
|
|
|
|
else:
|
|
|
|
install_efi_bin = "shim.efi"
|
|
|
|
|
2018-05-28 17:47:47 +02:00
|
|
|
# Copied, roughly, from openSUSE's install script,
|
|
|
|
# and pythonified. *disk* is something like /dev/sda,
|
|
|
|
# while *drive* may return "(disk/dev/sda,gpt1)" ..
|
|
|
|
# we're interested in the numbers in the second part
|
|
|
|
# of that tuple.
|
|
|
|
efi_drive = subprocess.check_output([
|
|
|
|
libcalamares.job.configuration["grubProbe"],
|
|
|
|
"-t", "drive", "--device-map=", install_efi_directory])
|
|
|
|
efi_disk = subprocess.check_output([
|
|
|
|
libcalamares.job.configuration["grubProbe"],
|
|
|
|
"-t", "disk", "--device-map=", install_efi_directory])
|
|
|
|
|
|
|
|
efi_drive_partition = efi_drive.replace("(","").replace(")","").split(",")[1]
|
|
|
|
# Get the first run of digits from the partition
|
|
|
|
efi_partititon_number = None
|
|
|
|
c = 0
|
|
|
|
start = None
|
|
|
|
while c < len(efi_drive_partition):
|
|
|
|
if efi_drive_partition[c].isdigit() and start is None:
|
|
|
|
start = c
|
|
|
|
if not efi_drive_partition[c].isdigit() and start is not None:
|
|
|
|
efi_drive_number = efi_drive_partition[start:c]
|
|
|
|
break
|
|
|
|
c += 1
|
|
|
|
if efi_partititon_number is None:
|
|
|
|
raise ValueError("No partition number found for %s" % install_efi_directory)
|
|
|
|
|
2018-02-20 16:47:14 +01:00
|
|
|
subprocess.call([
|
2018-06-17 07:47:58 +02:00
|
|
|
libcalamares.job.configuration["efiBootMgr"],
|
2018-02-20 16:47:14 +01:00
|
|
|
"-c",
|
|
|
|
"-w",
|
|
|
|
"-L", efi_bootloader_id,
|
2018-05-28 17:47:47 +02:00
|
|
|
"-d", efi_disk,
|
|
|
|
"-p", efi_partititon_number,
|
2018-05-28 15:26:20 +02:00
|
|
|
"-l", install_efi_directory + "/" + install_efi_bin])
|
2018-02-20 16:47:14 +01:00
|
|
|
|
2018-02-20 10:22:35 +01:00
|
|
|
|
2016-09-16 16:30:17 +02:00
|
|
|
def vfat_correct_case(parent, name):
|
|
|
|
for candidate in os.listdir(parent):
|
|
|
|
if name.lower() == candidate.lower():
|
2016-11-05 17:41:38 +01:00
|
|
|
return os.path.join(parent, candidate)
|
2016-09-16 16:30:17 +02:00
|
|
|
return os.path.join(parent, name)
|
2016-08-23 10:20:52 +02:00
|
|
|
|
|
|
|
|
2015-02-20 00:28:44 +01:00
|
|
|
def prepare_bootloader(fw_type):
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Prepares bootloader.
|
2017-03-16 16:59:28 +01:00
|
|
|
Based on value 'efi_boot_loader', it either calls systemd-boot
|
|
|
|
or grub to be installed.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param fw_type:
|
|
|
|
:return:
|
|
|
|
"""
|
2015-02-20 00:32:46 +01:00
|
|
|
efi_boot_loader = libcalamares.job.configuration["efiBootLoader"]
|
2015-02-20 00:33:16 +01:00
|
|
|
efi_directory = libcalamares.globalstorage.value("efiSystemPartition")
|
2015-06-14 05:08:52 +02:00
|
|
|
|
|
|
|
if efi_boot_loader == "systemd-boot" and fw_type == "efi":
|
2015-06-11 00:32:34 +02:00
|
|
|
install_systemd_boot(efi_directory)
|
2018-02-20 10:22:35 +01:00
|
|
|
elif efi_boot_loader == "sb-shim" and fw_type == "efi":
|
|
|
|
install_secureboot(efi_directory)
|
|
|
|
elif efi_boot_loader == "grub" or fw_type != "efi":
|
2015-02-20 01:00:31 +01:00
|
|
|
install_grub(efi_directory, fw_type)
|
2018-02-20 10:22:35 +01:00
|
|
|
else:
|
|
|
|
libcalamares.utils.debug( "WARNING: the combination of "
|
|
|
|
"boot-loader '{!s}' and firmware '{!s}' "
|
|
|
|
"is not supported.".format(efi_boot_loader, fw_type) )
|
2014-10-12 19:45:02 +02:00
|
|
|
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
def run():
|
2017-03-24 16:39:25 +01:00
|
|
|
"""
|
|
|
|
Starts procedure and passes 'fw_type' to other routine.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2015-07-07 19:15:48 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
fw_type = libcalamares.globalstorage.value("firmwareType")
|
2017-01-17 18:13:51 +01:00
|
|
|
|
2017-03-24 16:39:25 +01:00
|
|
|
if (libcalamares.globalstorage.value("bootLoader") is None
|
|
|
|
and fw_type != "efi"):
|
2017-01-17 18:13:51 +01:00
|
|
|
return None
|
|
|
|
|
2017-02-17 16:20:43 +01:00
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
|
|
|
|
|
|
|
if fw_type == "efi":
|
|
|
|
esp_found = False
|
|
|
|
|
|
|
|
for partition in partitions:
|
2017-03-29 20:19:41 +02:00
|
|
|
if (partition["mountPoint"] ==
|
2017-03-24 16:39:25 +01:00
|
|
|
libcalamares.globalstorage.value("efiSystemPartition")):
|
2017-02-17 16:20:43 +01:00
|
|
|
esp_found = True
|
|
|
|
|
|
|
|
if not esp_found:
|
|
|
|
return None
|
|
|
|
|
2015-02-20 00:28:44 +01:00
|
|
|
prepare_bootloader(fw_type)
|
2015-06-14 05:08:52 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
return None
|