summaryrefslogtreecommitdiffstats
path: root/src/utils/boot.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-02-27 13:24:35 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-04 11:33:10 +0100
commit66941e9f7956452d5d63bd87c8dbeb7d307924f3 (patch)
tree82c517d78571a5c86e756d8f788ae79c565b2aaa /src/utils/boot.py
parent23b4b1feb631b805afc8bf55e206fa6f753e646c (diff)
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.
Diffstat (limited to 'src/utils/boot.py')
-rw-r--r--src/utils/boot.py39
1 files 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)