summaryrefslogtreecommitdiffstats
path: root/src/utils/disk.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/disk.py')
-rw-r--r--src/utils/disk.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils/disk.py b/src/utils/disk.py
index e26983c..f4dc0ce 100644
--- a/src/utils/disk.py
+++ b/src/utils/disk.py
@@ -34,3 +34,27 @@ def get_partition_device(disknum, partnum):
return cxt.partition_to_string(pa, fdisk.FDISK_FIELD_DEVICE)
raise ValueError('No such partition')
+
+
+def get_efi_partition(disknum):
+ """
+ Look for an EFI System Partition at the n-th disk. If disknum is invalid an exception is thrown
+
+ Returns tuple with:
+ - Device name containing the ESP
+ - /dev/{device} string
+ - Partition number (starting at 1)
+ """
+ try:
+ disk = get_disks()[disknum-1]
+ cxt = fdisk.Context(f'/dev/{disk}')
+
+ if cxt.label == fdisk.FDISK_DISKLABEL_DOS:
+ raise RuntimeError('Disk has DOS partition scheme, cannot find ESP.')
+
+ for pa in cxt.partitions:
+ if pa.type.name == 'EFI System':
+ return cxt.partition_to_string(pa, fdisk.FDISK_FIELD_DEVICE), f'/dev/{disk}', pa.partno + 1
+ except:
+ logging.error(f'Unable to find efi partition at disk number {disknum}')
+ raise