diff options
Diffstat (limited to 'src/utils/boot.py')
-rw-r--r-- | src/utils/boot.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/utils/boot.py b/src/utils/boot.py index 9ce5238..6ee7450 100644 --- a/src/utils/boot.py +++ b/src/utils/boot.py @@ -17,13 +17,14 @@ from src.utils.disk import get_partition_device, get_efi_partition from src.utils.bios import * from src.utils.uefi import * from src.utils.fs import * +from src.log import OgError def _boot_bios_linux(disk, part, mountpoint): logging.info(f'Booting Linux system') if not get_linux_distro_id(mountpoint) == 'ubuntu': - raise NotImplementedError(f'{os_probe(mountpoint)} detected, only Ubuntu is supported for legacy BIOS boot') + raise OgError(f'{os_probe(mountpoint)} detected, only Ubuntu is supported for legacy BIOS boot') kernel_path = get_vmlinuz_path(mountpoint) initrd_path = get_initrd_path(mountpoint) @@ -39,7 +40,7 @@ def _boot_bios_linux(disk, part, mountpoint): subprocess.run(shlex.split(kexec_cmd), check=True, text=True) subprocess.run(shlex.split(kexec_reboot_cmd), check=True, text=True) except OSError as e: - raise OSError(f'Error processing kexec: {e}') from e + raise OgError(f'Error processing kexec: {e}') from e def _boot_bios_windows(disk, part, mountpoint): logging.info(f'Booting Windows system') @@ -52,7 +53,7 @@ def _boot_bios_windows(disk, part, mountpoint): with open(f'{mountpoint}/ogboot.secondboot', 'w') as f: f.write('\0' * (3072)) except OSError as e: - raise OSError(f'Could not create ogboot files in Windows partition: {e}') from e + raise OgError(f'Could not create ogboot files in Windows partition: {e}') from e def _boot_uefi_windows(disk, part, mountpoint): logging.info(f'Booting windows system') @@ -60,7 +61,7 @@ def _boot_uefi_windows(disk, part, mountpoint): 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): - raise RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}') + raise OgError(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'] @@ -71,7 +72,7 @@ def _boot_uefi_windows(disk, part, mountpoint): logging.info(f'Found bootloader at ESP partition: {loader}') break else: - raise RuntimeError(f'Unable to locate Windows EFI bootloader bootmgfw.efi') + raise OgError(f'Unable to locate Windows EFI bootloader bootmgfw.efi') efibootmgr_delete_bootentry(bootlabel) efibootmgr_create_bootentry(esp_disk, esp_part_number, loader, bootlabel) @@ -85,7 +86,7 @@ def _boot_uefi_linux(disk, part, mountpoint): esp, esp_disk, esp_part_number = get_efi_partition(disk, enforce_gpt=False) 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}') + raise OgError(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'] @@ -96,7 +97,7 @@ def _boot_uefi_linux(disk, part, mountpoint): logging.info(f'Found bootloader at ESP partition: {loader}') break else: - raise RuntimeError(f'Unable to locate Linux EFI bootloader shimx64.efi') + raise OgError(f'Unable to locate Linux EFI bootloader shimx64.efi') efibootmgr_delete_bootentry(bootlabel) efibootmgr_create_bootentry(esp_disk, esp_part_number, loader, bootlabel) @@ -109,7 +110,7 @@ def boot_os_at(disk, part): device = get_partition_device(disk, part) mountpoint = device.replace('dev', 'mnt') if not mount_mkdir(device, mountpoint): - raise RuntimeError(f'Cannot probe OS family. Unable to mount {device} into {mountpoint}') + raise OgError(f'Cannot probe OS family. Unable to mount {device} into {mountpoint}') is_uefi = is_uefi_supported() if is_uefi: @@ -130,6 +131,6 @@ def boot_os_at(disk, part): elif not is_uefi and os_family == OSFamily.LINUX: _boot_bios_linux(disk, part, mountpoint) else: - raise RuntimeError(f'Unknown OS family {os_family}') + raise OgError(f'Unknown OS family {os_family}') finally: umount(mountpoint) |