|
4 | 4 | import re |
5 | 5 | import shlex |
6 | 6 | import shutil |
| 7 | +import stat |
7 | 8 | import subprocess |
8 | 9 | import textwrap |
9 | 10 | import time |
@@ -1329,14 +1330,6 @@ def _add_grub_bootloader( |
1329 | 1330 |
|
1330 | 1331 | self.pacman.strap('grub') |
1331 | 1332 |
|
1332 | | - grub_default = self.target / 'etc/default/grub' |
1333 | | - config = grub_default.read_text() |
1334 | | - |
1335 | | - kernel_parameters = ' '.join(self._get_kernel_params(root, False, False)) |
1336 | | - config = re.sub(r'(GRUB_CMDLINE_LINUX=")("\n)', rf'\1{kernel_parameters}\2', config, count=1) |
1337 | | - |
1338 | | - grub_default.write_text(config) |
1339 | | - |
1340 | 1333 | info(f'GRUB boot partition: {boot_partition.dev_path}') |
1341 | 1334 |
|
1342 | 1335 | boot_dir = Path('/boot') |
@@ -1394,6 +1387,50 @@ def _add_grub_bootloader( |
1394 | 1387 | except SysCallError as err: |
1395 | 1388 | raise DiskError(f'Failed to install GRUB boot on {boot_partition.dev_path}: {err}') |
1396 | 1389 |
|
| 1390 | + if SysInfo.has_uefi() and uki_enabled: |
| 1391 | + grub_d = self.target / 'etc/grub.d' |
| 1392 | + linux_file = grub_d / '10_linux' |
| 1393 | + uki_file = grub_d / '15_uki' |
| 1394 | + |
| 1395 | + raw_str_platform = r'\$grub_platform' |
| 1396 | + space_indent_cmd = ' uki' |
| 1397 | + content = textwrap.dedent( |
| 1398 | + f"""\ |
| 1399 | + #! /bin/sh |
| 1400 | + set -e |
| 1401 | +
|
| 1402 | + cat << EOF |
| 1403 | + if [ "{raw_str_platform}" = "efi" ]; then |
| 1404 | + {space_indent_cmd} |
| 1405 | + fi |
| 1406 | + EOF |
| 1407 | + """, |
| 1408 | + ) |
| 1409 | + |
| 1410 | + try: |
| 1411 | + mode = linux_file.stat().st_mode |
| 1412 | + linux_file.chmod(mode & ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) |
| 1413 | + uki_file.write_text(content) |
| 1414 | + uki_file.chmod(mode) |
| 1415 | + except OSError: |
| 1416 | + error('Failed to enable UKI menu entries') |
| 1417 | + else: |
| 1418 | + grub_default = self.target / 'etc/default/grub' |
| 1419 | + config = grub_default.read_text() |
| 1420 | + |
| 1421 | + kernel_parameters = ' '.join( |
| 1422 | + self._get_kernel_params(root, id_root=False, partuuid=False), |
| 1423 | + ) |
| 1424 | + config = re.sub( |
| 1425 | + r'^(GRUB_CMDLINE_LINUX=")(")$', |
| 1426 | + rf'\1{kernel_parameters}\2', |
| 1427 | + config, |
| 1428 | + count=1, |
| 1429 | + flags=re.MULTILINE, |
| 1430 | + ) |
| 1431 | + |
| 1432 | + grub_default.write_text(config) |
| 1433 | + |
1397 | 1434 | try: |
1398 | 1435 | self.arch_chroot( |
1399 | 1436 | f'grub-mkconfig -o {boot_dir}/grub/grub.cfg', |
|
0 commit comments