refs #1594 indent some comments
parent
c1dc47f160
commit
acf2c1dc49
|
@ -70,7 +70,7 @@ def ogCreatePartitions (disk, parts):
|
||||||
|
|
||||||
SECTORS = ogGetLastSector (disk)
|
SECTORS = ogGetLastSector (disk)
|
||||||
|
|
||||||
# Se recalcula el nº de sectores del disco 1, si existe partición de caché.
|
# Se recalcula el nº de sectores del disco si existe partición de caché.
|
||||||
CACHESIZE = 0
|
CACHESIZE = 0
|
||||||
CACHEPART = CacheLib.ogFindCache()
|
CACHEPART = CacheLib.ogFindCache()
|
||||||
if CACHEPART:
|
if CACHEPART:
|
||||||
|
@ -78,7 +78,7 @@ def ogCreatePartitions (disk, parts):
|
||||||
if ND == cache_disk:
|
if ND == cache_disk:
|
||||||
CACHESIZE = int (CacheLib.ogGetCacheSize()) * 2
|
CACHESIZE = int (CacheLib.ogGetCacheSize()) * 2
|
||||||
|
|
||||||
# Sector de inicio (la partición 1 empieza en el sector 63).
|
# Sector de inicio (la partición 1 empieza en el sector 63).
|
||||||
IODISCO = ogDiskToDev (disk)
|
IODISCO = ogDiskToDev (disk)
|
||||||
IOSIZE = 0
|
IOSIZE = 0
|
||||||
fdisk_out = subprocess.run (['fdisk', '-l', IODISCO], capture_output=True, text=True).stdout
|
fdisk_out = subprocess.run (['fdisk', '-l', IODISCO], capture_output=True, text=True).stdout
|
||||||
|
@ -101,12 +101,12 @@ def ogCreatePartitions (disk, parts):
|
||||||
|
|
||||||
PART = 1
|
PART = 1
|
||||||
|
|
||||||
# Fichero temporal de entrada para "sfdisk"
|
# Fichero temporal de entrada para "sfdisk"
|
||||||
sfdisk_input = 'unit: sectors\n\n'
|
sfdisk_input = 'unit: sectors\n\n'
|
||||||
|
|
||||||
NVME_PREFIX = 'p' if 'nvme' in DISK else ''
|
NVME_PREFIX = 'p' if 'nvme' in DISK else ''
|
||||||
|
|
||||||
# Generar fichero de entrada para "sfdisk" con las particiones.
|
# Generar fichero de entrada para "sfdisk" con las particiones.
|
||||||
for p in parts:
|
for p in parts:
|
||||||
# Conservar los datos de la partición de caché.
|
# Conservar los datos de la partición de caché.
|
||||||
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
||||||
|
@ -148,6 +148,8 @@ def ogCreatePartitions (disk, parts):
|
||||||
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={START}, size={SIZE}, Id={ID}\n'
|
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={START}, size={SIZE}, Id={ID}\n'
|
||||||
# Error si se supera el nº total de sectores.
|
# Error si se supera el nº total de sectores.
|
||||||
START += SIZE
|
START += SIZE
|
||||||
|
|
||||||
|
# Error si se supera el nº total de sectores.
|
||||||
if '4096' == IOSIZE and PART > 4:
|
if '4096' == IOSIZE and PART > 4:
|
||||||
START += 2048
|
START += 2048
|
||||||
if START > SECTORS:
|
if START > SECTORS:
|
||||||
|
@ -155,24 +157,25 @@ def ogCreatePartitions (disk, parts):
|
||||||
return None
|
return None
|
||||||
PART += 1
|
PART += 1
|
||||||
|
|
||||||
# Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché.
|
# Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché.
|
||||||
while PART <= 4:
|
while PART <= 4:
|
||||||
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
||||||
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, Id=ca\n'
|
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, Id=ca\n'
|
||||||
else:
|
else:
|
||||||
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start=0, size=0, Id=0\n'
|
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start=0, size=0, Id=0\n'
|
||||||
PART += 1
|
PART += 1
|
||||||
# Si se define partición extendida sin lógicas, crear particion 5 vacía.
|
# Si se define partición extendida sin lógicas, crear particion 5 vacía.
|
||||||
if 5 == PART and EXTSTART:
|
if 5 == PART and EXTSTART:
|
||||||
sfdisk_input += f'{DISK}5 : start={EXTSTART}, SIZE={EXTSIZE}, Id=0\n'
|
sfdisk_input += f'{DISK}5 : start={EXTSTART}, SIZE={EXTSIZE}, Id=0\n'
|
||||||
|
|
||||||
# Desmontar los sistemas de archivos del disco antes de realizar las operaciones.
|
# Desmontar los sistemas de archivos del disco antes de realizar las operaciones.
|
||||||
FileSystemLib.ogUnmountAll (ND)
|
FileSystemLib.ogUnmountAll (ND)
|
||||||
if CACHESIZE: CacheLib.ogUnmountCache()
|
if CACHESIZE: CacheLib.ogUnmountCache()
|
||||||
|
|
||||||
# Si la tabla de particiones no es valida, volver a generarla.
|
# Si la tabla de particiones no es valida, volver a generarla.
|
||||||
ogCreatePartitionTable (ND)
|
ogCreatePartitionTable (ND)
|
||||||
# Definir particiones y notificar al kernel.
|
|
||||||
|
# Definir particiones y notificar al kernel.
|
||||||
print (f'about to run sfdisk: ({sfdisk_input})')
|
print (f'about to run sfdisk: ({sfdisk_input})')
|
||||||
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
|
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
|
||||||
print (f'rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
|
print (f'rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
|
||||||
|
@ -198,7 +201,6 @@ def ogCreatePartitions (disk, parts):
|
||||||
#@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc.
|
#@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def ogCreateGptPartitions (disk, parts):
|
def ogCreateGptPartitions (disk, parts):
|
||||||
# Nº total de sectores, para evitar desbordamiento (evitar redondeo).
|
|
||||||
ND = disk
|
ND = disk
|
||||||
DISK = ogDiskToDev (ND)
|
DISK = ogDiskToDev (ND)
|
||||||
if not DISK: return None
|
if not DISK: return None
|
||||||
|
@ -225,7 +227,7 @@ def ogCreateGptPartitions (disk, parts):
|
||||||
DELOPTIONS = []
|
DELOPTIONS = []
|
||||||
OPTIONS = []
|
OPTIONS = []
|
||||||
for p in parts:
|
for p in parts:
|
||||||
# Si PART es la cache, nos la saltamos y seguimos con el siguiente numero para conservar los datos de la partición de caché.
|
# Conservar los datos de la partición de caché.
|
||||||
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
|
||||||
PART += 1
|
PART += 1
|
||||||
|
|
||||||
|
@ -284,9 +286,7 @@ def ogCreateGptPartitions (disk, parts):
|
||||||
# Borramos primero las particiones y luego creamos las nuevas
|
# Borramos primero las particiones y luego creamos las nuevas
|
||||||
subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK])
|
subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK])
|
||||||
subprocess.run (['partprobe', DISK])
|
subprocess.run (['partprobe', DISK])
|
||||||
|
|
||||||
if CACHESIZE: CacheLib.ogMountCache()
|
if CACHESIZE: CacheLib.ogMountCache()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue