mirror of https://git.48k.eu/ogclient
utils: improve logging in the get_efi_partition function
Log each partition that gets checked and make the exception messages more informative.master
parent
673cada250
commit
aa34704b4d
|
@ -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}')
|
||||
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.')
|
||||
|
||||
if cxt.label == fdisk.FDISK_DISKLABEL_DOS:
|
||||
raise RuntimeError('Disk has DOS partition scheme, cannot find ESP.')
|
||||
disk = get_disks()[disk_index]
|
||||
cxt = fdisk.Context(f'/dev/{disk}')
|
||||
|
||||
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
|
||||
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}')
|
||||
|
|
Loading…
Reference in New Issue