refs #2441 remove "sgdisk" call in ogCreateCache
parent
38be98d9f1
commit
df36d74d7c
|
@ -42,7 +42,7 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
return None
|
||||
SIZE = 2 * sizecache
|
||||
# Inicio partición cache según el disco tenga sectores de 4k o menores
|
||||
IOSIZE = DiskLib.ogGetIoSize (DISK)
|
||||
IOSIZE = DiskLib.ogGetIoSize (ndsk)
|
||||
if not IOSIZE:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Failed to get disk sector size')
|
||||
return None
|
||||
|
@ -89,30 +89,32 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
|||
subprocess.run (['gdisk', DISK], input='2\nw\nY\n', capture_output=True, text=True)
|
||||
# Si existe la cache se borra previamente
|
||||
if ogFindCache(): ogDeleteCache()
|
||||
# Capturamos el codigo de particion GPT para cache
|
||||
# PATCH - Cuando es GPT, la particion con codigo CACHE (CA00) no existe y no puede crearse, se cambia por LINUX (8300)
|
||||
ID = DiskLib.ogTypeToId ('LINUX', 'GPT')
|
||||
subprocess.run (['sgdisk', DISK, f'-n{part}:{START}:{END}', f'-c{part}:CACHE', f'-t{part}:{ID}'])
|
||||
|
||||
ID = DiskLib.ogTypeToId ('LINUX', 'GPT_GUID')
|
||||
sfdisk_line = f'{DISK}{NVME_PREFIX}{part} : start= {START}, size= {SIZE}, type={ID}, name=CACHE'
|
||||
elif 'MSDOS' == get_ptt:
|
||||
# Si la tabla de particiones no es valida, volver a generarla.
|
||||
if subprocess.run (['parted', '-s', DISK, 'print']).returncode: ## if True, then parted failed
|
||||
subprocess.run (['fdisk', DISK], input='w\n', text=True)
|
||||
# Definir particiones y notificar al kernel.
|
||||
|
||||
ID = DiskLib.ogTypeToId ('CACHE', 'MSDOS')
|
||||
# Salvamos la configuración de las particiones e incluimos la cache.
|
||||
tmp = subprocess.run (['sfdisk', '--dump', DISK], capture_output=True, text=True).stdout.splitlines()
|
||||
tmp = [ x for x in tmp if f'{DISK}{part}' not in x ]
|
||||
tmp.append (f'{DISK}{NVME_PREFIX}{part} : start= {START}, size= {SIZE}, Id={ID}')
|
||||
# Ordenamos las líneas de los dispositivos
|
||||
UNIT = [ x for x in tmp if 'unit' in x ][0]
|
||||
tmp = sorted ([ x for x in tmp if re.match ('^/dev', x) ])
|
||||
tmp = [UNIT, ''] + tmp
|
||||
# Guardamos nueva configuración en el disco.
|
||||
i = '\n'.join(tmp)
|
||||
subprocess.run (['sfdisk', '--no-reread', DISK], input=i, text=True)
|
||||
sfdisk_line = f'{DISK}{NVME_PREFIX}{part} : start= {START}, size= {SIZE}, Id={ID}'
|
||||
else:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, 'No hay tabla de particiones en el disco')
|
||||
return False
|
||||
|
||||
# Salvamos la configuración de las particiones e incluimos la cache.
|
||||
tmp = subprocess.run (['sfdisk', '--dump', DISK], capture_output=True, text=True).stdout.splitlines()
|
||||
tmp = [ x for x in tmp if f'{DISK}{part}' not in x ] ## grep -v la_de_cache
|
||||
tmp.append (sfdisk_line)
|
||||
# Ordenamos las líneas de los dispositivos
|
||||
UNIT = [ x for x in tmp if 'unit' in x ][0]
|
||||
tmp = sorted ([ x for x in tmp if re.match ('^/dev', x) ])
|
||||
tmp = [UNIT, ''] + tmp
|
||||
# Guardamos nueva configuración en el disco.
|
||||
i = '\n'.join(tmp)
|
||||
subprocess.run (['sfdisk', '--no-reread', DISK], input=i, text=True)
|
||||
|
||||
# Actualiza la tabla de particiones en el kernel.
|
||||
DiskLib.ogUpdatePartitionTable()
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue