diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-04-23 01:02:39 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-07-29 15:07:22 +0200 |
commit | 7ab965c0b57bf829c42ed54b84213d2c01f135b3 (patch) | |
tree | 076a6f30e3ff6c4f2cc0c272700a98146bb63a25 /src | |
parent | 4f31bde5499d962332a31817a2e1fd31fd00fe5d (diff) |
utils: add restore_windows_efi_bootloader
Add restore_windows_efi_bootloader to copy the EFI loader from
the filesystem in the restored system into the EFI partition.
This commit is preparatory work for the new native postinstall code.
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/uefi.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils/uefi.py b/src/utils/uefi.py index 48fb6c3..5ca8270 100644 --- a/src/utils/uefi.py +++ b/src/utils/uefi.py @@ -162,3 +162,34 @@ def copy_windows_efi_bootloader(disk, partition): finally: umount(mountpoint) umount(esp_mountpoint) + + +def restore_windows_efi_bootloader(disk, partition): + device = get_partition_device(disk, partition) + mountpoint = device.replace('dev', 'mnt') + if not mount_mkdir(device, mountpoint): + raise OgError(f'Cannot probe OS family. Unable to mount {device} into {mountpoint}') + + bootlabel = f'Part-{disk:02d}-{partition:02d}' + esp, esp_disk, esp_part_number = get_efi_partition(disk, enforce_gpt=True) + esp_mountpoint = esp.replace('dev', 'mnt') + if not mount_mkdir(esp, esp_mountpoint): + umount(mountpoint) + raise OgError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}') + + try: + loader_dir = f'{mountpoint}/ogBoot' + destination_dir = f'{esp_mountpoint}/EFI/{bootlabel}/Boot' + if os.path.exists(destination_dir): + try: + shutil.rmtree(destination_dir) + except OSError as e: + raise OgError(f'Failed to delete {destination_dir}: {e}') from e + logging.info(f'Copying {loader_dir} into {destination_dir}') + try: + shutil.copytree(loader_dir, destination_dir) + except OSError as e: + raise OgError(f'Failed to copy {loader_dir} into {destination_dir}: {e}') from e + finally: + umount(mountpoint) + umount(esp_mountpoint)
\ No newline at end of file |