summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utils/disk.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/utils/disk.py b/src/utils/disk.py
index 02c63fc..0848cff 100644
--- a/src/utils/disk.py
+++ b/src/utils/disk.py
@@ -7,6 +7,7 @@
# (at your option) any later version.
import os
+import logging
import fdisk
@@ -45,16 +46,18 @@ def get_efi_partition(disknum):
- /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
+ disk_index = disknum - 1
+ if disk_index < 0 or disk_index >= len(get_disks()):
+ raise ValueError(f'Invalid disk number {disknum} when trying to find ESP, {len(get_disks())} disks available.')
+
+ disk = get_disks()[disk_index]
+ cxt = fdisk.Context(f'/dev/{disk}')
+
+ if 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:
+ logging.info(f'Checking partition "{pa.type.name}"...')
+ if pa.type.name == 'EFI System':
+ return cxt.partition_to_string(pa, fdisk.FDISK_FIELD_DEVICE), f'/dev/{disk}', pa.partno + 1
+ raise RuntimeError(f'Cannot find "EFI System" partition at /dev/{disk}')