refs #1166 add ogWindowsBootParameters()
parent
39ad37e324
commit
ceb82ef24e
|
@ -6,10 +6,16 @@
|
|||
#@warning License: GNU GPLv3+
|
||||
#*/
|
||||
|
||||
import re
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
import ogGlobals
|
||||
import SystemLib
|
||||
import FileSystemLib
|
||||
import RegistryLib
|
||||
import DiskLib
|
||||
import InventoryLib
|
||||
|
||||
#/**
|
||||
# ogBoot int_ndisk int_nfilesys [ NVRAMPERM ] [str_kernel str_initrd str_krnlparams]
|
||||
|
@ -148,6 +154,150 @@ def ogSetWindowsName (disk, par, name):
|
|||
#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
|
||||
#*/ ##
|
||||
|
||||
def ogWindowsBootParameters (disk, par):
|
||||
if not DiskLib.ogDiskToDev (disk, par):
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, '')
|
||||
return
|
||||
|
||||
disk0 = int (disk) - 1
|
||||
|
||||
tmpfile = tempfile.NamedTemporaryFile (prefix='ogWBP-', mode='w').name
|
||||
if InventoryLib.ogIsEfiActive():
|
||||
bootdisk, bootpar = DiskLib.ogGetEsp().split()
|
||||
if not FileSystemLib.ogUnmount (bootdisk, bootpar):
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'ESP: {bootdisk} {bootpar}')
|
||||
return
|
||||
bootdisk = str (int (bootdisk) - 1)
|
||||
bootlabel = f'Part-{int(bootdisk):02d}-{int(bootpar):02d}'
|
||||
bcdfile = f'boot_BCD_file=/EFI/{bootlabel}/Boot/BCD'
|
||||
else:
|
||||
bootdisk = disk0
|
||||
bootpar = par
|
||||
bcdfile = ''
|
||||
|
||||
|
||||
# Obtener versión de Windows.
|
||||
winver = InventoryLib.ogGetOsVersion (disk, par)
|
||||
parts = re.split (':| ', winver)
|
||||
if 'Windows' == parts[0] and 'Server' == parts[2]:
|
||||
winver = parts[1] + parts[2] + parts[3]
|
||||
else:
|
||||
winver = parts[1] + parts[2]
|
||||
if not winver:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTOS, 'Windows')
|
||||
return
|
||||
|
||||
# Acciones para Windows XP.
|
||||
if 'XP' in winver:
|
||||
m = FileSystemLib.ogMount (disk, par)
|
||||
if not m or not os.path.exists (f'{m}/boot.ini'):
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, 'boot.ini')
|
||||
return
|
||||
with open (f'{m}/boot.ini', 'r') as fd:
|
||||
boot_ini = fd.read()
|
||||
boot_ini = re.sub (r'partition\([0-9]\)', f'partition({par})', boot_ini)
|
||||
boot_ini = re.sub (r'rdisk\([0-9]\)', f'rdisk({disk0})', boot_ini)
|
||||
with open (f'{m}/tmp.boot.ini', 'w') as fd:
|
||||
fd.write (boot_ini)
|
||||
os.rename (f'{m}/tmp.boot.ini', f'{m}/boot.ini')
|
||||
return True
|
||||
|
||||
if not FileSystemLib.ogUnmount (disk, par):
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, '')
|
||||
return
|
||||
|
||||
|
||||
#Preparando instruccion Windows Resume Application
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={disk0}
|
||||
main_part={par}
|
||||
boot_entry=Windows Resume Application
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
|
||||
#Preparando instruccion tipo windows
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={disk0}
|
||||
main_part={par}
|
||||
boot_entry={winver}
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
##Preparando instruccion Ramdisk Options
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={disk0}
|
||||
main_part={par}
|
||||
boot_entry=Ramdisk Options
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
##Preparando instruccion Recovery Environment
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={disk0}
|
||||
main_part={par}
|
||||
boot_entry=Windows Recovery Environment
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
##Preparando instruccion Recovery
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={disk0}
|
||||
main_part={par}
|
||||
boot_entry=Windows Recovery
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
#Preparando instruccion Windows Boot Manager
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={bootdisk}
|
||||
main_part={bootpar}
|
||||
boot_entry=Windows Boot Manager
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={bootdisk}
|
||||
main_part={bootpar}
|
||||
boot_entry=Herramienta de diagnóstico de memoria de Windows
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
|
||||
with open (tmpfile, 'w') as fd:
|
||||
fd.write (f"""boot_disk={bootdisk}
|
||||
boot_main_part={bootpar}
|
||||
{bcdfile}
|
||||
disk={bootdisk}
|
||||
main_part={bootpar}
|
||||
boot_entry=Herramienta de diagn<f3>stico de memoria de Windows
|
||||
""")
|
||||
subprocess.run (['timeout', '--foreground', '--signal=SIGKILL', '5s', 'spartlnx.run', '-cui', '-nm', '-w', '-f', tmpfile], stdin=subprocess.DEVNULL)
|
||||
|
||||
os.remove (tmpfile)
|
||||
|
||||
|
||||
|
||||
#/**
|
||||
|
|
|
@ -159,7 +159,7 @@ def ogRestoreEfiBootLoader (disk, par):
|
|||
|
||||
osversion = InventoryLib.ogGetOsVersion (disk, par)
|
||||
if 'Windows 1' in osversion:
|
||||
bootlabel = f'Part-{disk:02d}-{par:02d}'
|
||||
bootlabel = f'Part-{int(disk):02d}-{int(par):02d}'
|
||||
loader = FileLib.ogGetPath (f'{mntdir}/ogBoot/bootmgfw.efi')
|
||||
if not loader:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTOS, f'{disk} {par} ({osversion}, EFI)')
|
||||
|
|
Loading…
Reference in New Issue