diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/disk.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/disk.py b/src/utils/disk.py index a44153d..81faa07 100644 --- a/src/utils/disk.py +++ b/src/utils/disk.py @@ -8,6 +8,8 @@ import os import logging +import shlex +import subprocess from src.log import OgError import fdisk @@ -69,3 +71,26 @@ def get_efi_partition(disknum, enforce_gpt): if pa.type.name == 'EFI System': return cxt.partition_to_string(pa, fdisk.FDISK_FIELD_DEVICE), f'/dev/{disk}', pa.partno + 1 raise OgError(f'Cannot find "EFI System" partition at /dev/{disk}') + + +def get_partition_id(disk_index, part_index): + device = get_partition_device(disk_index, part_index) + cmd = f'blkid -s PARTUUID -o value {device}' + proc = subprocess.run(shlex.split(cmd), + stdout=subprocess.PIPE, + encoding='utf-8') + if proc.returncode != 0: + raise OgError(f'failed to query partition UUID for {device}') + return proc.stdout.strip() + + +def get_disk_id(disk_index): + disk = get_disks()[disk_index - 1] + disk_path = f'/dev/{disk}' + cmd = f'blkid -s PTUUID -o value {disk_path}' + proc = subprocess.run(shlex.split(cmd), + stdout=subprocess.PIPE, + encoding='utf-8') + if proc.returncode != 0: + raise OgError(f'failed to query disk UUID for {disk_path}') + return proc.stdout.strip() |