refs #1222 add ogGrubInstallPartition()
parent
b54877528c
commit
9c059ce407
|
@ -11,6 +11,7 @@ import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
|
import glob
|
||||||
|
|
||||||
import ogGlobals
|
import ogGlobals
|
||||||
import SystemLib
|
import SystemLib
|
||||||
|
@ -404,6 +405,84 @@ part_letter={registered_vol}
|
||||||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
|
||||||
|
def ogGrubInstallPartition (disk, par, checkos='FALSE', kernelparam=''):
|
||||||
|
backupname = '.backup.og'
|
||||||
|
|
||||||
|
version = InventoryLib.ogGetOsVersion (disk, par)
|
||||||
|
if not version or 'Linux' not in version:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTOS, 'no es linux')
|
||||||
|
return
|
||||||
|
|
||||||
|
firststage = DiskLib.ogDiskToDev (disk, par) #Localizar primera etapa del grub
|
||||||
|
secondstage = FileSystemLib.ogMount (disk, par) #localizar disco segunda etapa del grub
|
||||||
|
prefixsecondstage = '/boot/grubPARTITION' #Localizar directorio segunda etapa del grub
|
||||||
|
efioptgrub = [] # Si es EFI instalamos el grub en la ESP
|
||||||
|
#efibootdir = '' # Desde el bootdir uefi y bios buscan el grub.cfg en subdirectorios distintos.
|
||||||
|
|
||||||
|
if InventoryLib.ogIsEfiActive():
|
||||||
|
esp = DiskLib.ogGetEsp()
|
||||||
|
efidisk, efipart = esp.split()
|
||||||
|
efisecondstage = FileSystemLib.ogMount (efidisk, efipart)
|
||||||
|
if not efisecondstage:
|
||||||
|
FileSystemLib.ogFormat (efidisk, efipart, 'FAT32')
|
||||||
|
efisecondstage = FileSystemLib.ogMount (efidisk, efipart)
|
||||||
|
if not efisecondstage:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, 'ESP')
|
||||||
|
return
|
||||||
|
efisubdir = f'Part-{int(disk):02d}-{int(par):02d}'
|
||||||
|
if os.path.isdir (f'{efisecondstage}/EFI/{efisubdir}'): # Borramos la configuración anterior
|
||||||
|
shutil.rmtree (f'{efisecondstage}/EFI/{efisubdir}')
|
||||||
|
os.makedirs (f'{efisecondstage}/EFI/{efisubdir}/Boot')
|
||||||
|
arch = InventoryLib.ogGetArch()
|
||||||
|
efioptgrub = ['--removable', '--no-nvram', '--uefi-secure-boot', '--target', f'{arch}-efi', f'--efi-directory={efisecondstage}/EFI/{efisubdir}']
|
||||||
|
#efibootdir = '/boot'
|
||||||
|
|
||||||
|
# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
|
||||||
|
if 'FALSE' == checkos.upper() and (os.path.exists (f'{secondstage}/boot/grub/grub.cfg') or os.path.exists (f'{secondstage}/boot/grub/grub.cfg{backupname}')):
|
||||||
|
if os.path.exists (f'{secondstage}/boot/grub/grub.cfg{backupname}'):
|
||||||
|
os.rename (f'{secondstage}/boot/grub/grub.cfg{backupname}', f'{secondstage}/boot/grub/grub.cfg')
|
||||||
|
if os.path.isdir (f'{secondstage}{prefixsecondstage}'):
|
||||||
|
shutil.rmtree (f'{secondstage}{prefixsecondstage}')
|
||||||
|
prefixsecondstage = '' # Reactivamos el grub con el grub.cfg original.
|
||||||
|
else: # SI Reconfigurar segunda etapa (grub.cfg) == TRUE
|
||||||
|
if InventoryLib.ogIsEfiActive():
|
||||||
|
# UEFI: grubSintax necesita grub.cfg para detectar los kernels: si no existe recupero backup.
|
||||||
|
if not os.path.exists (f'{secondstage}/boot/grub/grub.cfg'):
|
||||||
|
if os.path.exists (f'{secondstage}/boot/grub/grub.cfg{backupname}'):
|
||||||
|
os.rename (f'{secondstage}/boot/grub/grub.cfg{backupname}', f'{secondstage}/boot/grub/grub.cfg')
|
||||||
|
else:
|
||||||
|
os.rename (f'{secondstage}/boot/grub/grub.cfg', f'{secondstage}/boot/grub/grub.cfg{backupname}')
|
||||||
|
|
||||||
|
with open ('/etc/default/grub', 'a') as fd: #Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
|
||||||
|
fd.write ('GRUB_DISABLE_RECOVERY="true"\n')
|
||||||
|
fd.write ('GRUB_DISABLE_LINUX_UUID="true"\n')
|
||||||
|
|
||||||
|
os.makedirs (f'{secondstage}{prefixsecondstage}/boot/grub/') #Preparar configuración segunda etapa: crear ubicacion
|
||||||
|
subprocess.run (['sed', '-i', 's/^set -e/#set -e/', '/etc/grub.d/00_header']) #Preparar configuración segunda etapa: crear cabecera del fichero (ingnorar errores)
|
||||||
|
# (ogLive 5.0) Si 'pkgdatadir' está vacía ponemos valor de otros ogLive
|
||||||
|
subprocess.run (['sed', '-i', '/grub-mkconfig_lib/i\pkgdatadir=${pkgdatadir:-"${datarootdir}/grub"}', '/etc/grub.d/00_header'])
|
||||||
|
out = subprocess.run (['/etc/grub.d/00_header'], capture_output=True, text=True).stdout
|
||||||
|
with open (f'{secondstage}{prefixsecondstage}/boot/grub/grub.cfg', 'w') as fd:
|
||||||
|
fd.write (out + '\n')
|
||||||
|
|
||||||
|
#Preparar configuración segunda etapa: crear entrada del sistema operativo
|
||||||
|
out = subprocess.run (['grubSyntax', disk, par, kernelparam], capture_output=True, text=True).stdout
|
||||||
|
with open (f'{secondstage}{prefixsecondstage}/boot/grub/grub.cfg', 'a') as fd:
|
||||||
|
fd.write (out + '\n')
|
||||||
|
|
||||||
|
eval = subprocess.run (['grub-install', '--force'] + efioptgrub + [f'--root-directory={secondstage}{prefixsecondstage}', firststage]).returncode
|
||||||
|
|
||||||
|
if InventoryLib.ogIsEfiActive(): # Movemos el grubx64.efi
|
||||||
|
for b in (glob.glob (f'{efisecondstage}/EFI/{efisubdir}/EFI/BOOT/*')):
|
||||||
|
os.rename (f'{efisecondstage}/EFI/{efisubdir}/EFI/BOOT/{b}', f'{efisecondstage}/EFI/{efisubdir}/Boot/{b}')
|
||||||
|
shutil.rmtree (f'{efisecondstage}/EFI/{efisubdir}/EFI')
|
||||||
|
shutil.copy2 ('/usr/lib/shim/shimx64.efi.signed', f'{efisecondstage}/EFI/{efisubdir}/Boot/shimx64.efi')
|
||||||
|
# Nombre OpenGnsys para cargador
|
||||||
|
shutil.copy2 (f'{efisecondstage}/EFI/{efisubdir}/Boot/grubx64.efi', f'{efisecondstage}/EFI/{efisubdir}/Boot/ogloader.efi')
|
||||||
|
|
||||||
|
return eval
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogConfigureFstab int_ndisk int_nfilesys
|
# ogConfigureFstab int_ndisk int_nfilesys
|
||||||
|
@ -444,15 +523,15 @@ def ogConfigureFstab (disk, par):
|
||||||
partswap = partswap.splitlines()[0]
|
partswap = partswap.splitlines()[0]
|
||||||
partswap = partswap.split (':')[0]
|
partswap = partswap.split (':')[0]
|
||||||
if defswap:
|
if defswap:
|
||||||
print ("Hay definicion de SWAP en el FSTAB $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP") # Mensaje temporal.
|
print ("Hay definicion de SWAP en el FSTAB $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP") # Mensaje temporal.
|
||||||
subprocess.run (f'sed "s|{defswap}|{partswap}|g; s|{defroot}|{partroot}|g" {fstab}.backup > {fstab}', shell=True)
|
subprocess.run (f'sed "s|{defswap}|{partswap}|g; s|{defroot}|{partroot}|g" {fstab}.backup > {fstab}', shell=True)
|
||||||
else:
|
else:
|
||||||
print ("No hay definicion de SWAP y si hay partición SWAP -> moficamos fichero") # Mensaje temporal.
|
print ("No hay definicion de SWAP y si hay partición SWAP -> moficamos fichero") # Mensaje temporal.
|
||||||
subprocess.run (f'sed "s|{defroot}|{partroot}|g" {fstab}.backup > {fstab}', shell=True)
|
subprocess.run (f'sed "s|{defroot}|{partroot}|g" {fstab}.backup > {fstab}', shell=True)
|
||||||
with open ('/etc/fstab', 'a') as fd:
|
with open ('/etc/fstab', 'a') as fd:
|
||||||
fd.write (f'{partswap} none swap sw 0 0\n')
|
fd.write (f'{partswap} none swap sw 0 0\n')
|
||||||
else:
|
else:
|
||||||
print ("No hay partición SWAP -> configuramos FSTAB") # Mensaje temporal.
|
print ("No hay partición SWAP -> configuramos FSTAB") # Mensaje temporal.
|
||||||
subprocess.run (f'sed "/swap/d" {fstab}.backup > {fstab}', shell=True)
|
subprocess.run (f'sed "/swap/d" {fstab}.backup > {fstab}', shell=True)
|
||||||
# Si es un sistema EFI incluimos partición ESP (Si existe la modificamos)
|
# Si es un sistema EFI incluimos partición ESP (Si existe la modificamos)
|
||||||
if InventoryLib.ogIsEfiActive():
|
if InventoryLib.ogIsEfiActive():
|
||||||
|
|
|
@ -30,14 +30,10 @@ import FileLib
|
||||||
#@return str_arch - Arquitectura (i386 para 32 bits, x86_64 para 64 bits).
|
#@return str_arch - Arquitectura (i386 para 32 bits, x86_64 para 64 bits).
|
||||||
#*/
|
#*/
|
||||||
def ogGetArch():
|
def ogGetArch():
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
if os.path.isdir ('/lib64'):
|
||||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0], sys.argv[0] + " => x86_64")
|
return 'x86_64'
|
||||||
return
|
|
||||||
|
|
||||||
if platform.machine().endswith("64"):
|
|
||||||
print("x86_64")
|
|
||||||
else:
|
else:
|
||||||
print("i386")
|
return 'i386'
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
|
|
Loading…
Reference in New Issue