Refactor `_add_systemd_bootloader()` entries creation (#1907)

This commit is contained in:
codefiles 2023-06-30 08:36:38 -04:00 committed by GitHub
parent a0e4e6ee76
commit a04e68495b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 60 additions and 49 deletions

View File

@ -736,31 +736,29 @@ class Installer:
entries_dir = loader_dir / 'entries' entries_dir = loader_dir / 'entries'
entries_dir.mkdir(parents=True, exist_ok=True) entries_dir.mkdir(parents=True, exist_ok=True)
for kernel in self.kernels: comments = (
for variant in ("", "-fallback"): '# Created by: archinstall\n',
# Setup the loader entry f'# Created on: {self.init_time}\n'
with open(entries_dir / f'{self.init_time}_{kernel}{variant}.conf', 'w') as entry: )
entry.write('# Created by: archinstall\n')
entry.write(f'# Created on: {self.init_time}\n') microcode = []
entry.write(f'title Arch Linux ({kernel}{variant})\n')
entry.write(f"linux /vmlinuz-{kernel}\n")
if not SysInfo.is_vm(): if not SysInfo.is_vm():
vendor = SysInfo.cpu_vendor() vendor = SysInfo.cpu_vendor()
if vendor == "AuthenticAMD": if vendor == "AuthenticAMD":
entry.write("initrd /amd-ucode.img\n") microcode.append('initrd /amd-ucode.img\n')
elif vendor == "GenuineIntel": elif vendor == "GenuineIntel":
entry.write("initrd /intel-ucode.img\n") microcode.append('initrd /intel-ucode.img\n')
else: else:
debug( debug(
f"Unknown CPU vendor '{vendor}' detected.", f"Unknown CPU vendor '{vendor}' detected.",
"Archinstall won't add any ucode to systemd-boot config.", "Archinstall won't add any ucode to systemd-boot config.",
) )
entry.write(f"initrd /initramfs-{kernel}{variant}.img\n")
# blkid doesn't trigger on loopback devices really well, # blkid doesn't trigger on loopback devices really well,
# so we'll use the old manual method until we get that sorted out. # so we'll use the old manual method until we get that sorted out.
options_entry = f'rw rootfstype={root_partition.safe_fs_type.fs_type_mount} {" ".join(self._kernel_params)}\n' options_entry = f'rw rootfstype={root_partition.safe_fs_type.fs_type_mount} {" ".join(self._kernel_params)}'
for sub_vol in root_partition.btrfs_subvols: for sub_vol in root_partition.btrfs_subvols:
if sub_vol.is_root(): if sub_vol.is_root():
@ -776,21 +774,34 @@ class Installer:
# or simply a partition encryption. Right now we assume it's a partition (and we always have) # or simply a partition encryption. Right now we assume it's a partition (and we always have)
debug('Root partition is an encrypted device, identifying by PARTUUID: {root_partition.partuuid}') debug('Root partition is an encrypted device, identifying by PARTUUID: {root_partition.partuuid}')
kernel_options = f"options"
if self._disk_encryption and self._disk_encryption.hsm_device: if self._disk_encryption and self._disk_encryption.hsm_device:
# Note: lsblk UUID must be used, not PARTUUID for sd-encrypt to work # Note: lsblk UUID must be used, not PARTUUID for sd-encrypt to work
kernel_options += f' rd.luks.name={root_partition.uuid}=luksdev' kernel_options = f'rd.luks.name={root_partition.uuid}=luksdev'
# Note: tpm2-device and fido2-device don't play along very well: # Note: tpm2-device and fido2-device don't play along very well:
# https://github.com/archlinux/archinstall/pull/1196#issuecomment-1129715645 # https://github.com/archlinux/archinstall/pull/1196#issuecomment-1129715645
kernel_options += f' rd.luks.options=fido2-device=auto,password-echo=no' kernel_options += ' rd.luks.options=fido2-device=auto,password-echo=no'
else: else:
kernel_options += f' cryptdevice=PARTUUID={root_partition.partuuid}:luksdev' kernel_options = f'cryptdevice=PARTUUID={root_partition.partuuid}:luksdev'
entry.write(f'{kernel_options} root=/dev/mapper/luksdev {options_entry}') cmdline = f'{kernel_options} root=/dev/mapper/luksdev {options_entry}'
else: else:
debug(f'Identifying root partition by PARTUUID: {root_partition.partuuid}') debug(f'Identifying root partition by PARTUUID: {root_partition.partuuid}')
entry.write(f'options root=PARTUUID={root_partition.partuuid} {options_entry}') cmdline = f'root=PARTUUID={root_partition.partuuid} {options_entry}'
for kernel in self.kernels:
for variant in ("", "-fallback"):
# Setup the loader entry
with open(entries_dir / f'{self.init_time}_{kernel}{variant}.conf', 'w') as entry:
entry_lines: List[str] = []
entry_lines.extend(comments)
entry_lines.append(f'title Arch Linux ({kernel}{variant})\n')
entry_lines.append(f'linux /vmlinuz-{kernel}\n')
entry_lines.extend(microcode)
entry_lines.append(f'initrd /initramfs-{kernel}{variant}.img\n')
entry_lines.append(f'options {cmdline}\n')
entry.writelines(entry_lines)
self.helper_flags['bootloader'] = 'systemd' self.helper_flags['bootloader'] = 'systemd'