mirror of https://git.48k.eu/ogclient
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.master
parent
4f31bde549
commit
7ab965c0b5
|
@ -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)
|
Loading…
Reference in New Issue