Skip to content

Commit 60d4370

Browse files
committed
Enable GRUB UKI menu entries
1 parent 0aca992 commit 60d4370

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

archinstall/lib/installer.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import shlex
66
import shutil
7+
import stat
78
import subprocess
89
import textwrap
910
import time
@@ -1329,14 +1330,6 @@ def _add_grub_bootloader(
13291330

13301331
self.pacman.strap('grub')
13311332

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-
13401333
info(f'GRUB boot partition: {boot_partition.dev_path}')
13411334

13421335
boot_dir = Path('/boot')
@@ -1394,6 +1387,50 @@ def _add_grub_bootloader(
13941387
except SysCallError as err:
13951388
raise DiskError(f'Failed to install GRUB boot on {boot_partition.dev_path}: {err}')
13961389

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+
13971434
try:
13981435
self.arch_chroot(
13991436
f'grub-mkconfig -o {boot_dir}/grub/grub.cfg',

0 commit comments

Comments
 (0)