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.
master
Alejandro Sirgo Rica 2024-02-27 13:24:35 +01:00
parent 23b4b1feb6
commit 66941e9f79
1 changed files with 33 additions and 6 deletions

View File

@ -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)