Fix Bootloader installation (#2032)

* Fix broken path

* Update

* Update

---------

Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
Daniel Girtler 2023-09-14 20:05:53 +10:00 committed by GitHub
parent dcf3dfef57
commit 0258b0335e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 19 deletions

View File

@ -117,6 +117,10 @@ class DeviceHandler(object):
return part
return None
def get_parent_device_path(self, dev_path: Path) -> Path:
lsblk = get_lsblk_info(dev_path)
return Path(f'/dev/{lsblk.pkname}')
def get_uuid_for_path(self, path: Path) -> Optional[str]:
partition = self.find_partition(path)
return partition.partuuid if partition else None

View File

@ -1083,7 +1083,6 @@ def get_lsblk_info(dev_path: Union[Path, str]) -> LsblkInfo:
def get_all_lsblk_info() -> List[LsblkInfo]:
return _fetch_lsblk_info()
def get_lsblk_by_mountpoint(mountpoint: Path, as_prefix: bool = False) -> List[LsblkInfo]:
def _check(infos: List[LsblkInfo]) -> List[LsblkInfo]:
devices = []

View File

@ -880,17 +880,31 @@ class Installer:
self.pacman.strap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead?
try:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory={boot_partition.mountpoint} --bootloader-id=GRUB --removable', peek_output=True)
SysCommand(
f'/usr/bin/arch-chroot {self.target} grub-install '
f'--debug '
f'--target=x86_64-efi '
f'--efi-directory={boot_partition.mountpoint} '
f'--bootloader-id=GRUB '
f'--removable',
peek_output=True
)
except SysCallError:
try:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory={boot_partition.mountpoint} --bootloader-id=GRUB --removable', peek_output=True)
SysCommand(
f'/usr/bin/arch-chroot {self.target} '
f'grub-install '
f'--debug '
f'--target=x86_64-efi '
f'--efi-directory={boot_partition.mountpoint} '
f'--bootloader-id=GRUB '
f'--removable',
peek_output=True
)
except SysCallError as err:
raise DiskError(f"Could not install GRUB to {self.target}{boot_partition.mountpoint}: {err}")
else:
device = disk.device_handler.get_device_by_partition_path(boot_partition.safe_dev_path)
if not device:
raise ValueError(f'Can not find block device: {boot_partition.safe_dev_path}')
parent_dev_path = disk.device_handler.get_parent_device_path(boot_partition.safe_dev_path)
try:
cmd = f'/usr/bin/arch-chroot' \
@ -898,14 +912,17 @@ class Installer:
f' grub-install' \
f' --debug' \
f' --target=i386-pc' \
f' --recheck {device.device_info.path}'
f' --recheck {parent_dev_path}'
SysCommand(cmd, peek_output=True)
except SysCallError as err:
raise DiskError(f"Failed to install GRUB boot on {boot_partition.dev_path}: {err}")
try:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-mkconfig -o {boot_partition.mountpoint}/grub/grub.cfg')
SysCommand(
f'/usr/bin/arch-chroot {self.target} '
f'grub-mkconfig -o {boot_partition.mountpoint}/grub/grub.cfg'
)
except SysCallError as err:
raise DiskError(f"Could not configure GRUB: {err}")
@ -923,10 +940,6 @@ class Installer:
# partition before the format.
root_uuid = get_lsblk_info(root_partition.safe_dev_path).uuid
device = disk.device_handler.get_device_by_partition_path(boot_partition.safe_dev_path)
if not device:
raise ValueError(f'Can not find block device: {boot_partition.safe_dev_path}')
def create_pacman_hook(contents: str):
HOOK_DIR = "/etc/pacman.d/hooks"
SysCommand(f"/usr/bin/arch-chroot {self.target} mkdir -p {HOOK_DIR}")
@ -940,6 +953,8 @@ class Installer:
f' cp' \
f' /usr/share/limine/BOOTX64.EFI' \
f' /boot/EFI/BOOT/'
SysCommand(cmd, peek_output=True)
except SysCallError as err:
raise DiskError(f"Failed to install Limine BOOTX64.EFI on {boot_partition.dev_path}: {err}")
@ -957,6 +972,8 @@ When = PostTransaction
Exec = /usr/bin/cp /usr/share/limine/BOOTX64.EFI /boot/EFI/BOOT/
""")
else:
parent_dev_path = disk.device_handler.get_parent_device_path(boot_partition.safe_dev_path)
try:
# The `limine.sys` file, contains stage 3 code.
cmd = f'/usr/bin/arch-chroot' \
@ -972,7 +989,7 @@ Exec = /usr/bin/cp /usr/share/limine/BOOTX64.EFI /boot/EFI/BOOT/
f' {self.target}' \
f' limine' \
f' bios-install' \
f' {device.device_info.path}'
f' {parent_dev_path}'
SysCommand(cmd, peek_output=True)
except SysCallError as err:
@ -1062,13 +1079,10 @@ TIMEOUT=5
debug(f'Root partition is an encrypted device identifying by PARTUUID: {root_partition.partuuid}')
kernel_parameters.append(f'root=PARTUUID={root_partition.partuuid} rw rootfstype={root_partition.safe_fs_type.value} {" ".join(self._kernel_params)}')
device = disk.device_handler.get_device_by_partition_path(boot_partition.safe_dev_path)
if not device:
raise ValueError(f'Unable to find block device: {boot_partition.safe_dev_path}')
parent_dev_path = disk.device_handler.get_parent_device_path(boot_partition.safe_dev_path)
cmd = f'efibootmgr ' \
f'--disk {device.device_info.path} ' \
f'--disk {parent_dev_path} ' \
f'--part {boot_partition.safe_dev_path} ' \
f'--create ' \
f'--label "{label}" ' \