mirror of https://git.48k.eu/ogclient
utils: add functions to obtain disk and partition UUIDs
Add get_partition_id and get_disk_id to obtain the UUID of a disk or partition as a string. These values are obtained invoking the program blkid as a subprocess. This commit is preparatory work for the new native postinstall code.master
parent
41b5f830c6
commit
4f31bde549
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue