summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/live/ogOperations.py2
-rw-r--r--src/utils/legacy.py10
-rw-r--r--src/utils/uefi.py52
3 files changed, 53 insertions, 11 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 364f3bd..a3df4c8 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -461,7 +461,7 @@ class OgLiveOperations:
if os.access(f'{image_path}', os.R_OK) == True:
logging.info(f'image file {image_path} already exists, updating.')
- ogCopyEfiBootLoader(disk, partition)
+ copy_windows_efi_bootloader(disk, partition)
if ogReduceFs(disk, partition) == -1:
raise ValueError(f'Failed to shrink {fstype} filesystem in {padev}')
diff --git a/src/utils/legacy.py b/src/utils/legacy.py
index 76fc6c6..e740450 100644
--- a/src/utils/legacy.py
+++ b/src/utils/legacy.py
@@ -243,13 +243,3 @@ def configureOs(disk, partition):
raise OSError(f'Error processing configureOsCustom: {e}') from e
return out
-
-
-def ogCopyEfiBootLoader(disk, partition):
- cmd = f'ogCopyEfiBootLoader {disk} {partition}'
- try:
- proc = subprocess.run(cmd,
- shell=True,
- check=True)
- except OSError as e:
- raise OSError(f'Error processing ogCopyEfiBootLoader: {e}') from e
diff --git a/src/utils/uefi.py b/src/utils/uefi.py
index 9bc2e09..5561a6a 100644
--- a/src/utils/uefi.py
+++ b/src/utils/uefi.py
@@ -11,6 +11,10 @@ import logging
import os
import shlex
import subprocess
+import shutil
+from src.utils.disk import *
+from src.utils.fs import *
+from src.utils.probe import *
import fdisk
@@ -96,3 +100,51 @@ def efibootmgr_create_bootentry(disk, part, loader, label, add_to_bootorder=True
proc = subprocess.run(shlex.split(efibootmgr_cmd), check=True, text=True)
except OSError as e:
raise OSError(f'Unexpected error adding boot entry to nvram. UEFI firmware might be buggy') from e
+
+
+def copy_windows_efi_bootloader(disk, partition):
+ device = get_partition_device(disk, partition)
+ mountpoint = device.replace('dev', 'mnt')
+ if not mount_mkdir(device, mountpoint):
+ raise RuntimeError(f'Cannot probe OS family. Unable to mount {device} at {esp_mountpoint}')
+
+ os_family = get_os_family(mountpoint)
+ is_uefi = is_uefi_supported()
+
+ if not is_uefi or os_family != OSFamily.WINDOWS:
+ return
+
+ 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 RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}')
+
+ loader_paths = [f'{esp_mountpoint}/EFI/{bootlabel}/Boot/bootmgfw.efi',
+ f'{esp_mountpoint}/EFI/Microsoft/Boot/bootmgfw.efi']
+ try:
+ for efi_app in loader_paths:
+ logging.info(f'Searching for {efi_app}')
+ if os.path.exists(efi_app):
+ loader = efi_app
+ logging.info(f'Found bootloader at ESP partition: {loader}')
+ break
+ else:
+ raise RuntimeError(f'Unable to locate Windows EFI bootloader bootmgfw.efi')
+
+ loader_dir = os.path.dirname(loader)
+ destination_dir = f'{mountpoint}/ogBoot'
+ if os.path.exists(destination_dir):
+ try:
+ shutil.rmtree(destination_dir)
+ except Exception as e:
+ raise OSError(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 Exception as e:
+ raise OSError(f'Failed to copy {loader_dir} into {destination_dir}: {e}') from e
+ finally:
+ umount(mountpoint)
+ umount(esp_mountpoint)