summaryrefslogtreecommitdiffstats
path: root/src/utils/uefi.py
Commit message (Collapse)AuthorAgeFilesLines
* utils: add restore_windows_efi_bootloaderAlejandro Sirgo Rica2024-07-291-0/+31
| | | | | | | 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.
* utils: consolidate code to find efi loaderAlejandro Sirgo Rica2024-07-291-10/+23
| | | | | Add find_windows_efi_loader and find_linux_efi_loader to reduce code duplication and to centralize efi loader path modifications.
* src: use explicit exception types in except Exception blocksAlejandro Sirgo Rica2024-04-031-2/+2
| | | | | | | | Capture only the relevant exception types in each except block. The capture of the Exception type means hiding information for unhandled error cases, even for syntax errors in the codebase. Using a more fine grained exception filtering improves error traceability.
* src: log backtrace in unhandled error casesAlejandro Sirgo Rica2024-04-031-9/+10
| | | | | | | | | | | | | | | | | | | Log an error message in known error cases and log a backtrace otherwise. Define a new error type OgError to be used in all the 'raise' blocks to define the error message to log. The exception propagates until it reaches send_internal_server_error() where the exception type is checked. If the type is OgError we log the exception message. Logs the backtrace for other types. The initial error implementation printed a backtrace everytime an error ocurred. The next iteration changed it to only print a backtrace in a very particular case but ended up omiting too much information such as syntax errors or unknown error context. The actual implementation only logs the cases we already cover in the codebase and logs a bracktrace in the others, enabling a better debugging experience.
* utils: fix mount error messages for os probe operationsAlejandro Sirgo Rica2024-04-011-1/+1
| | | | | | | | Replace unexistent mountpoint variable to report a failed mount operation before an OS probe from a partition. Improve the semantics of the error message replacing 'at' with 'into'. Remove the period at the end of the log message.
* utils: drop ogCopyEfiBootLoader scriptAlejandro Sirgo Rica2024-03-261-0/+52
| | | | | | | | Implement a Python equivalent of ogCopyEfiBootLoader as the function copy_efi_bootloader. This function copies the contents of the folder of the EFI loader in the ESP into a ogBoot folder at the root of the partition target of an image creation. copy_efi_bootloader is a Windows only functionality.
* revert 7f18485: improve uefi detection mechanismAlejandro Sirgo Rica2024-03-261-12/+2
| | | | | | | | | | | Make is_uefi_supported() only check for /sys/firmware/efi as get_efi_partition() will detect a missing ESP or an invalid partition scheme. Stop using get_efi_partition() inside is_uefi_supported() as the former is eventually called in every UEFI related code. UEFI supports both MBR and GPT as partition schemes and this is a required change to handle the particular case of Windows not being able to boot UEFI from a MBR partition scheme.
* src: centralize error logging into send_internal_server_errorAlejandro Sirgo Rica2024-03-211-3/+2
| | | | | | | | | | | | | | | | | | | | Use only the exception messages as the main resource for error messages. The previous error code had string duplication in the form of: logging.error('msg here') raise Exception('msg here') That approach also has the downside of having log duplication as it had the local logging.err() and a global logging.exception() inside send_internal_server_error capturing the exception message. The actual code only requires raising an exception with a proper error message. Improve exception messages to give more error context. Log every AssertionError as a backtrace. Use the 'raise Exception from e' syntax to modify the a previously raised exception 'e' into an exception with aditional context or different type. This also prevents the message that warns about newer exceptions being launch after an initial exception.
* utils: improve uefi detection mechanismAlejandro Sirgo Rica2024-03-081-2/+12
| | | | | | | Checking the existence /sys/firmware/efi as it might appear sometimes in BIOS installs if the BIOS configuration is not proper. Checking for the EFI partition is the safest method to veryfy the install type.
* uefi: update EFIBOOTMGR_BIN to use /opt/opengnsys/sbin/efibootmgrv1.3.2-6OpenGnSys Support Team2024-03-051-1/+1
| | | | debian package with json support provides the binary through this path, update it.
* uefi: define EFIBOOTMGR_BIN to ease changing the efibootmgr binaryAlejandro Sirgo Rica2024-03-041-9/+11
| | | | | | The json functionality proposed upstream might be merged one day in efibootmgr so deploying a fork would not be needed anymore. This change aims to ease the migration once that day comes.
* utils: add uefi.pyJose M. Guisado2024-03-041-0/+97
Add UEFI related utilities inside a new utility module: uefi.py _check_efibootmgr_json ====================== Check if the system efibootmgr executable supports JSON output. This is a private function used only by other functions from uefi.py. is_uefi_supported ================= Check if the system supports UEFI firmware. run_efibootmgr_json =================== Runs efibootmgr with json output support. Return the JSON output as a Python dict. efibootmgr_create_bootentry =========================== Create nvram boot entry. This bootentry is usually later set to boot next just once via "BootNext" nvram variable. efibootmgr_delete_bootentry =========================== Delete a nvram boot entry. Used to avoid duplicates when booting the same disk and partition from a given client. efibootmgr_bootnext =================== Set nvram "BootNext" variable to a given boot entry so after client reboot, PXE is not executed and the given boot entry takes precedence. Add dependency with efibootmgr version >= 18, and efibootmgr JSON output which is currently out of tree from util-linux repo.