Merge branch 'issue-1788' into calamares
This is in response to the issue, and cleans up a bunch of code, but does not actually resolve the issue (because I can't quite tell what the issue should be). SEE #1788
This commit is contained in:
commit
87e7233292
@ -28,7 +28,39 @@ def pretty_name():
|
||||
return _("Configuring mkinitcpio.")
|
||||
|
||||
|
||||
def cpuinfo():
|
||||
def detect_plymouth():
|
||||
"""
|
||||
Checks existence (runnability) of plymouth in the target system.
|
||||
|
||||
@return True if plymouth exists in the target, False otherwise
|
||||
"""
|
||||
# Used to only check existence of path /usr/bin/plymouth in target
|
||||
return target_env_call(["sh", "-c", "which plymouth"]) == 0
|
||||
|
||||
|
||||
class cpuinfo(object):
|
||||
"""
|
||||
Object describing the current CPU's characteristics. It may be
|
||||
be considered a named tuple, there's no behavior here.
|
||||
|
||||
Fields in the object:
|
||||
- is_intel (if it's definitely an Intel CPU)
|
||||
- is_amd (if it's definitely an AMD CPU)
|
||||
- number_of_cores
|
||||
It is possible for both is_* fields to be False.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.is_intel = False
|
||||
self.is_amd = False
|
||||
self.number_of_cores = 0
|
||||
|
||||
cpu = self._cpuinfo()
|
||||
self.is_intel = cpu['proc0']['vendor_id'].lower() == "genuineintel"
|
||||
self.is_amd = cpu['proc0']['vendor_id'].lower() == "authenticamd"
|
||||
self.number_of_cores = len(cpu)
|
||||
|
||||
@staticmethod
|
||||
def _cpuinfo():
|
||||
"""
|
||||
Return the information in /proc/cpuinfo as a dictionary in the following
|
||||
format:
|
||||
@ -59,14 +91,11 @@ def cpuinfo():
|
||||
return cpu_info
|
||||
|
||||
|
||||
def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
|
||||
def get_host_initcpio():
|
||||
"""
|
||||
Set up mkinitcpio.conf.
|
||||
|
||||
:param hooks:
|
||||
:param modules:
|
||||
:param files:
|
||||
:param root_mount_point:
|
||||
Reads the host system mkinitcpio.conf and returns all
|
||||
the lines from that file, or an empty list if it does
|
||||
not exist.
|
||||
"""
|
||||
hostfile = "/etc/mkinitcpio.conf"
|
||||
try:
|
||||
@ -76,48 +105,52 @@ def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
|
||||
libcalamares.utils.debug("Could not open host file '%s'" % hostfile)
|
||||
mklins = []
|
||||
|
||||
for i in range(len(mklins)):
|
||||
if mklins[i].startswith("HOOKS"):
|
||||
joined_hooks = ' '.join(hooks)
|
||||
mklins[i] = "HOOKS=\"{!s}\"".format(joined_hooks)
|
||||
elif mklins[i].startswith("MODULES"):
|
||||
joined_modules = ' '.join(modules)
|
||||
mklins[i] = "MODULES=\"{!s}\"".format(joined_modules)
|
||||
elif mklins[i].startswith("FILES"):
|
||||
joined_files = ' '.join(files)
|
||||
mklins[i] = "FILES=\"{!s}\"".format(joined_files)
|
||||
|
||||
path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
||||
|
||||
with open(path, "w") as mkinitcpio_file:
|
||||
mkinitcpio_file.write("\n".join(mklins) + "\n")
|
||||
return mklins
|
||||
|
||||
|
||||
def detect_plymouth():
|
||||
def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
|
||||
"""
|
||||
Checks existence (runnability) of plymouth in the target system.
|
||||
Set up mkinitcpio.conf.
|
||||
|
||||
@return True if plymouth exists in the target, False otherwise
|
||||
"""
|
||||
# Used to only check existence of path /usr/bin/plymouth in target
|
||||
return target_env_call(["sh", "-c", "which plymouth"]) == 0
|
||||
|
||||
|
||||
def modify_mkinitcpio_conf(partitions, root_mount_point):
|
||||
"""
|
||||
Modifies mkinitcpio.conf
|
||||
|
||||
:param partitions:
|
||||
:param hooks:
|
||||
:param modules:
|
||||
:param files:
|
||||
:param root_mount_point:
|
||||
"""
|
||||
cpu = cpuinfo()
|
||||
swap_uuid = ""
|
||||
btrfs = ""
|
||||
lvm2 = ""
|
||||
hooks = ["base", "udev", "autodetect", "modconf", "block", "keyboard",
|
||||
"keymap"]
|
||||
mklins = get_host_initcpio()
|
||||
|
||||
target_path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
||||
with open(target_path, "w") as mkinitcpio_file:
|
||||
for line in mklins:
|
||||
# Replace HOOKS, MODULES and FILES lines with what we
|
||||
# have found via find_initcpio_features()
|
||||
if line.startswith("HOOKS"):
|
||||
line = "HOOKS=\"{!s}\"".format(' '.join(hooks))
|
||||
elif line.startswith("MODULES"):
|
||||
line = "MODULES=\"{!s}\"".format(' '.join(modules))
|
||||
elif lines.startswith("FILES"):
|
||||
line = "FILES=\"{!s}\"".format(' '.join(files))
|
||||
mkinitcpio_file.write(line + "\n")
|
||||
|
||||
|
||||
def find_initcpio_features(partitions, root_mount_point):
|
||||
"""
|
||||
Returns a tuple (hooks, modules, files) needed to support
|
||||
the given @p partitions (filesystems types, encryption, etc)
|
||||
in the target.
|
||||
|
||||
:param partitions: (from GS)
|
||||
:param root_mount_point: (from GS)
|
||||
|
||||
:return 3-tuple of lists
|
||||
"""
|
||||
hooks = ["base", "udev", "autodetect", "modconf", "block", "keyboard", "keymap"]
|
||||
modules = []
|
||||
files = []
|
||||
|
||||
swap_uuid = ""
|
||||
uses_btrfs = False
|
||||
uses_lvm2 = False
|
||||
encrypt_hook = False
|
||||
openswap_hook = False
|
||||
unencrypted_separate_boot = False
|
||||
@ -137,10 +170,10 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
||||
openswap_hook = True
|
||||
|
||||
if partition["fs"] == "btrfs":
|
||||
btrfs = "yes"
|
||||
uses_btrfs = True
|
||||
|
||||
if "lvm2" in partition["fs"]:
|
||||
lvm2 = "yes"
|
||||
uses_lvm2 = True
|
||||
|
||||
if partition["mountPoint"] == "/" and "luksMapperName" in partition:
|
||||
encrypt_hook = True
|
||||
@ -162,7 +195,7 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
||||
):
|
||||
files.append("/crypto_keyfile.bin")
|
||||
|
||||
if lvm2:
|
||||
if uses_lvm2:
|
||||
hooks.append("lvm2")
|
||||
|
||||
if swap_uuid != "":
|
||||
@ -172,15 +205,12 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
||||
else:
|
||||
hooks.extend(["filesystems"])
|
||||
|
||||
if btrfs == "yes" and cpu['proc0']['vendor_id'].lower() != "genuineintel":
|
||||
modules.append("crc32c")
|
||||
elif (btrfs == "yes"
|
||||
and cpu['proc0']['vendor_id'].lower() == "genuineintel"):
|
||||
modules.append("crc32c-intel")
|
||||
if uses_btrfs:
|
||||
modules.append("crc32c-intel" if cpuinfo().is_intel else "crc32c")
|
||||
else:
|
||||
hooks.append("fsck")
|
||||
|
||||
write_mkinitcpio_lines(hooks, modules, files, root_mount_point)
|
||||
return (hooks, modules, files)
|
||||
|
||||
|
||||
def run():
|
||||
@ -201,6 +231,7 @@ def run():
|
||||
return (_("Configuration Error"),
|
||||
_("No root mount point is given for <pre>{!s}</pre> to use." ).format("initcpiocfg"))
|
||||
|
||||
modify_mkinitcpio_conf(partitions, root_mount_point)
|
||||
hooks, modules, files = find_initcpio_features(partitions, root_mount_point)
|
||||
write_mkinitcpio_lines(hooks, modules, files, root_mount_point)
|
||||
|
||||
return None
|
||||
|
@ -1,7 +1,13 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
# Writes a mkinitcpio.conf into the target system. It copies
|
||||
# the host system's /etc/mkinitcpio.conf, and replaces any
|
||||
# HOOKS, MODULES, and FILES lines with calculated values
|
||||
# based on what the installation (seems to) need.
|
||||
---
|
||||
type: "job"
|
||||
name: "initcpiocfg"
|
||||
interface: "python"
|
||||
script: "main.py"
|
||||
noconfig: true
|
||||
|
Loading…
Reference in New Issue
Block a user