[initcpiocfg,grubcfg,bootloader] Minor code improvements

This commit is contained in:
dalto 2023-08-20 10:39:36 -05:00
parent b97a5d535c
commit a9547af8e2
3 changed files with 19 additions and 26 deletions

View File

@ -136,8 +136,11 @@ def get_kernel_params(uuid):
cryptdevice_params = []
have_dracut = libcalamares.utils.target_env_call(["sh", "-c", "which dracut"]) == 0
uses_sd_encrypt = libcalamares.utils.target_env_call(["sh", "-c", "grep -q sd-encrypt /etc/mkinitcpio.conf"])
has_dracut = libcalamares.utils.target_env_call(["sh", "-c", "which dracut"]) == 0
uses_systemd_hook = libcalamares.utils.target_env_call(["sh", "-c",
"grep -q \"^HOOKS.*systemd\" /etc/mkinitcpio.conf"]) == 0
use_systemd_naming = has_dracut or uses_systemd_hook
# Take over swap settings:
# - unencrypted swap partition sets swap_uuid
@ -155,7 +158,7 @@ def get_kernel_params(uuid):
swap_outer_uuid = partition["luksUuid"]
if partition["mountPoint"] == "/" and has_luks:
if have_dracut or uses_sd_encrypt:
if use_systemd_naming or uses_sd_encrypt:
cryptdevice_params = [f"rd.luks.uuid={partition['luksUuid']}"]
else:
cryptdevice_params = [f"cryptdevice=UUID={partition['luksUuid']}:{partition['luksMapperName']}"]
@ -188,7 +191,7 @@ def get_kernel_params(uuid):
if swap_uuid:
kernel_params.append("resume=UUID={!s}".format(swap_uuid))
if have_dracut and swap_outer_uuid:
if use_systemd_naming and swap_outer_uuid:
kernel_params.append(f"rd.luks.uuid={swap_outer_uuid}")
if swap_outer_mappername:

View File

@ -135,13 +135,12 @@ def modify_grub_default(partitions, root_mount_point, distributor):
plymouth_bin = libcalamares.utils.target_env_call(
["sh", "-c", "which plymouth"]
)
mkinitcpio_systemd = libcalamares.utils.target_env_call(
["sh", "-c", "grep -q sd-encrypt /etc/mkinitcpio.conf"]
uses_systemd_hook = libcalamares.utils.target_env_call(
["sh", "-c", "grep -q \"^HOOKS.*systemd\" /etc/mkinitcpio.conf"]
)
# Shell exit value 0 means success
have_plymouth = plymouth_bin == 0
have_dracut = dracut_bin == 0
uses_sd_encrypt = mkinitcpio_systemd == 0
use_systemd_naming = dracut_bin == 0 or uses_systemd_hook == 0
use_splash = ""
swap_uuid = ""
@ -162,7 +161,7 @@ def modify_grub_default(partitions, root_mount_point, distributor):
cryptdevice_params = []
if have_dracut or uses_sd_encrypt:
if use_systemd_naming:
for partition in partitions:
if partition["fs"] == "linuxswap" and not partition.get("claimed", None):
# Skip foreign swap
@ -213,7 +212,7 @@ def modify_grub_default(partitions, root_mount_point, distributor):
if swap_uuid:
kernel_params.append(f"resume=UUID={swap_uuid}")
if have_dracut and swap_outer_uuid:
if use_systemd_naming and swap_outer_uuid:
kernel_params.append(f"rd.luks.uuid={swap_outer_uuid}")
if swap_outer_mappername:
kernel_params.append(f"resume=/dev/mapper/{swap_outer_mappername}")

View File

@ -36,25 +36,17 @@ def detect_plymouth():
# Used to only check existence of path /usr/bin/plymouth in target
return target_env_call(["sh", "-c", "which plymouth"]) == 0
def detect_systemd():
"""
Checks existence (runnability) of systemd in the target system.
@return True if systemd exists in the target, False otherwise
"""
# Used to only check existence of path /usr/bin/systemd-cat in target
return target_env_call(["sh", "-c", "which systemd-cat"]) == 0
def detect_setfont():
"""
Checks existence (runnability) of setfont in the target system.
@return True if setfont exists in the target, False otherwise
"""
# Used to only check existence of path /usr/bin/setfont in target
return target_env_call(["sh", "-c", "which setfont"]) == 0
class cpuinfo(object):
"""
Object describing the current CPU's characteristics. It may be
@ -171,8 +163,7 @@ def find_initcpio_features(partitions, root_mount_point):
"block",
"keyboard",
]
uses_systemd = detect_systemd()
have_setfont = detect_setfont()
uses_systemd = target_env_call(["sh", "-c", "which systemd-cat"]) == 0
if uses_systemd:
hooks.insert(0, "systemd")
@ -182,15 +173,15 @@ def find_initcpio_features(partitions, root_mount_point):
hooks.insert(0, "base")
hooks.append("keymap")
hooks.append("consolefont")
modules = []
files = []
binaries = []
if have_setfont:
if detect_setfont():
# Fixes "setfont: KDFONTOP: Function not implemented" error
binaries.append("setfont")
swap_uuid = ""
uses_btrfs = False
uses_zfs = False
@ -226,7 +217,7 @@ def find_initcpio_features(partitions, root_mount_point):
if partition["mountPoint"] == "/" and "luksMapperName" in partition:
encrypt_hook = True
if (partition["mountPoint"] == "/boot" and "luksMapperName" not in partition):
if partition["mountPoint"] == "/boot" and "luksMapperName" not in partition:
unencrypted_separate_boot = True
if partition["mountPoint"] == "/usr":