summaryrefslogtreecommitdiffstats
path: root/src/utils/uefi.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/uefi.py')
-rw-r--r--src/utils/uefi.py31
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