MCPcopy Index your code
hub / github.com/archlinux/archinstall / _add_systemd_bootloader

Method _add_systemd_bootloader

archinstall/lib/installer.py:1241–1328  ·  view source on GitHub ↗
(
		self,
		boot_partition: PartitionModification,
		root: PartitionModification | LvmVolume,
		efi_partition: PartitionModification | None,
		uki_enabled: bool = False,
	)

Source from the content-addressed store, hash-verified

1239 entry_conf.write_text(entry_template.format(kernel=kernel))
1240
1241 def _add_systemd_bootloader(
1242 self,
1243 boot_partition: PartitionModification,
1244 root: PartitionModification | LvmVolume,
1245 efi_partition: PartitionModification | None,
1246 uki_enabled: bool = False,
1247 ) -> None:
1248 debug('Installing systemd bootloader')
1249
1250 self.pacman.strap('efibootmgr')
1251
1252 if not SysInfo.has_uefi():
1253 raise HardwareIncompatibilityError
1254
1255 if not efi_partition:
1256 raise ValueError('Could not detect EFI system partition')
1257 elif not efi_partition.mountpoint:
1258 raise ValueError('EFI system partition is not mounted')
1259
1260 # TODO: Ideally we would want to check if another config
1261 # points towards the same disk and/or partition.
1262 # And in which case we should do some clean up.
1263 bootctl_options = []
1264
1265 if boot_partition != efi_partition:
1266 bootctl_options.append(f'--esp-path={efi_partition.mountpoint}')
1267 bootctl_options.append(f'--boot-path={boot_partition.mountpoint}')
1268
1269 # TODO: This is a temporary workaround to deal with https://github.com/archlinux/archinstall/pull/3396#issuecomment-2996862019
1270 # the systemd_version check can be removed once `--variables=BOOL` is merged into systemd.
1271 systemd_pkg = installed_package('systemd')
1272
1273 # keep the version as a str as it can be something like 257.8-2
1274 if systemd_pkg is not None:
1275 systemd_version = systemd_pkg.version
1276 else:
1277 systemd_version = '257' # This works as a safety workaround for this hot-fix
1278
1279 try:
1280 # Force EFI variables since bootctl detects arch-chroot
1281 # as a container environment since v257 and skips them silently.
1282 # https://github.com/systemd/systemd/issues/36174
1283 if systemd_version >= '258':
1284 self.arch_chroot(f'bootctl --variables=yes {" ".join(bootctl_options)} install')
1285 else:
1286 self.arch_chroot(f'bootctl {" ".join(bootctl_options)} install')
1287 except SysCallError:
1288 if systemd_version >= '258':
1289 # Fallback, try creating the boot loader without touching the EFI variables
1290 self.arch_chroot(f'bootctl --variables=no {" ".join(bootctl_options)} install')
1291 else:
1292 self.arch_chroot(f'bootctl --no-variables {" ".join(bootctl_options)} install')
1293
1294 # Loader configuration is stored in ESP/loader:
1295 # https://man.archlinux.org/man/loader.conf.5
1296 loader_conf = self.target / efi_partition.relative_mountpoint / 'loader/loader.conf'
1297 # Ensure that the ESP/loader/ directory exists before trying to create a file in it
1298 loader_conf.parent.mkdir(parents=True, exist_ok=True)

Callers 1

add_bootloaderMethod · 0.95

Calls 7

arch_chrootMethod · 0.95
_create_bls_entriesMethod · 0.95
debugFunction · 0.90
installed_packageFunction · 0.90
strapMethod · 0.80
has_uefiMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected