diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-03-26 11:46:54 +0100 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-03-26 13:23:04 +0100 |
commit | 97647c32aa2c61107230528d448bfa1e56da0f73 (patch) | |
tree | 33bbb5bbf16b298c3e92e2f6781c63e22407a568 /src/utils/disk.py | |
parent | 42791a1a7ce08851a92db16ae8d7ce11ee8fb09b (diff) |
utils: add enforce_gpt argument to get_efi_partition()
The Windows bootloader only supports a UEFI boot from a GPT
partition. Set enforce_gpt to True in every codepath related to
Windows. When enforce_gpt is set to True get_efi_partition()
raises an exception when an MBR partition scheme is detected.
Diffstat (limited to 'src/utils/disk.py')
-rw-r--r-- | src/utils/disk.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/utils/disk.py b/src/utils/disk.py index b4541cc..99cf36f 100644 --- a/src/utils/disk.py +++ b/src/utils/disk.py @@ -41,9 +41,12 @@ def get_partition_device(disknum, partnum): raise ValueError(f'No such partition with disk index {disknum} and partition index {partnum}') -def get_efi_partition(disknum): +def get_efi_partition(disknum, enforce_gpt): """ - Look for an EFI System Partition at the n-th disk. If disknum is invalid an exception is thrown + Look for an EFI System Partition at the n-th disk. If disknum is invalid an + exception is thrown. + If enforce_gpt is set to True the ESP will be ignored in a MBR partition + scheme. Returns tuple with: - Device name containing the ESP @@ -57,7 +60,7 @@ def get_efi_partition(disknum): disk = get_disks()[disk_index] cxt = fdisk.Context(f'/dev/{disk}') - if cxt.label == fdisk.FDISK_DISKLABEL_DOS: + if enforce_gpt and cxt.label == fdisk.FDISK_DISKLABEL_DOS: raise RuntimeError(f'Disk has DOS partition scheme, cannot find ESP at /dev/{disk}') for pa in cxt.partitions: |