From 66941e9f7956452d5d63bd87c8dbeb7d307924f3 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 27 Feb 2024 13:24:35 +0100 Subject: live: drop IniciarSesion script when uefi booting into linux Replace IniciarSesion script in favor of native Python code when booting a UEFI system into Linux. This completes the implementation of booting into an OS on a UEFI compliant system. --- src/utils/boot.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/utils/boot.py b/src/utils/boot.py index 5a02ec6..cd66357 100644 --- a/src/utils/boot.py +++ b/src/utils/boot.py @@ -43,6 +43,30 @@ def _boot_uefi_windows(disk, part, mountpoint): finally: umount(esp_mountpoint) +def _boot_uefi_linux(disk, part, mountpoint): + logging.info(f'Booting Linux system') + bootlabel = f'Part-{disk:02d}-{part:02d}' + esp, esp_disk, esp_part_number = get_efi_partition(disk) + esp_mountpoint = esp.replace('dev', 'mnt') + if not mount_mkdir(esp, esp_mountpoint): + raise RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}') + + loader_paths = [f'{esp_mountpoint}/EFI/{bootlabel}/Boot/shimx64.efi', + f'{esp_mountpoint}/EFI/ubuntu/shimx64.efi'] + try: + for efi_app in loader_paths: + if os.path.exists(efi_app): + loader = efi_app[len(esp_mountpoint):] + logging.info(f'Found bootloader at ESP partition: {loader}') + break + else: + raise RuntimeError(f'Unable to locate Linux EFI bootloader shimx64.efi') + + efibootmgr_delete_bootentry(bootlabel) + efibootmgr_create_bootentry(esp_disk, esp_part_number, loader, bootlabel) + efibootmgr_bootnext(bootlabel) + finally: + umount(esp_mountpoint) def boot_os_at(disk, part): if not is_uefi_supported(): @@ -55,9 +79,12 @@ def boot_os_at(disk, part): logging.info(f'Booting system at {device}. Probing OS family...') os_family = get_os_family(mountpoint) - if os_family == OSFamily.WINDOWS: - _boot_uefi_windows(disk, part, mountpoint) - elif os_family == OSFamily.LINUX: - raise NotImplementedError('WIP: Linux UEFI boot not implemented yet.') - else: - raise RuntimeError('Unknown OS family') + try: + if os_family == OSFamily.WINDOWS: + _boot_uefi_windows(disk, part, mountpoint) + elif os_family == OSFamily.LINUX: + _boot_uefi_linux(disk, part, mountpoint) + else: + raise RuntimeError('Unknown OS family') + finally: + umount(mountpoint) -- cgit v1.2.3-18-g5258