refs #1622 add ogGrub4dosInstallMbr
parent
842b4a395b
commit
7e255b6c52
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from BootLib import ogGrub4dosInstallMbr
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogGrub4dosInstallMbr', 'ogGrub4dosInstallMbr int_ndisk int_part', ['ogGrub4dosInstallMbr 1 1'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
ret = ogGrub4dosInstallMbr (args.disk, args.par)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
|
@ -1282,3 +1282,54 @@ def ogBootLoaderSetTimeOut (disk, par, timeout):
|
||||||
#@exception OG_ERR_NOMSDOS Disco duro no particioniado en modo msdos
|
#@exception OG_ERR_NOMSDOS Disco duro no particioniado en modo msdos
|
||||||
#@exception OG_ERR_NOTWRITE Particion no modificable.
|
#@exception OG_ERR_NOTWRITE Particion no modificable.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
|
||||||
|
def ogGrub4dosInstallMbr (disk, par):
|
||||||
|
#Controlar existencia de disco y particion
|
||||||
|
DEVICE = DiskLib.ogDiskToDev (disk)
|
||||||
|
if not DEVICE:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, '')
|
||||||
|
return None
|
||||||
|
MOUNTDISK = FileSystemLib.ogMount (disk, par)
|
||||||
|
if not MOUNTDISK:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, ogGlobals.lang.MSG_ERROR)
|
||||||
|
return None
|
||||||
|
#Controlar acceso de escritura a la particion
|
||||||
|
if FileSystemLib.ogIsReadonly (disk, par):
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTWRITE, f': {disk} {par}')
|
||||||
|
return None
|
||||||
|
#Controlar disco no uefi
|
||||||
|
if InventoryLib.ogIsEfiActive():
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTBIOS, ' : grub4dos solo soporta PC con bios legacy')
|
||||||
|
return None
|
||||||
|
#Controlar particionado tipo msdos
|
||||||
|
ptt = DiskLib.ogGetPartitionTableType (disk)
|
||||||
|
if 'MSDOS' != ptt:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOMSDOS, ': grub2dos requiere particionado tipo MSDOS')
|
||||||
|
return None
|
||||||
|
#Controlar la existencia del grub4dos con acceso a ntfs
|
||||||
|
BINDIR = f'{ogGlobals.OGLIB}/grub4dos/grub4dos-0.4.6a'
|
||||||
|
if not os.path.exists (f'{BINDIR}/bootlace.com'):
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f': {BINDIR}/bootlace.com')
|
||||||
|
return None
|
||||||
|
|
||||||
|
#instalar el bootloader de grlrd en el MBR
|
||||||
|
subprocess.run ([f'{BINDIR}/bootlace64.com', DEVICE], capture_output=True)
|
||||||
|
#copiar grld a la particion
|
||||||
|
shutil.copy2 (f'{BINDIR}/grldr', MOUNTDISK)
|
||||||
|
#Instalar y configurar grub4dos
|
||||||
|
if os.path.exists (f'{MOUNTDISK}/boot/grub/menu.lst'):
|
||||||
|
os.unlink (f'{MOUNTDISK}/boot/grub/menu.lst')
|
||||||
|
os.rmdir (f'/{MOUNTDISK}/boot/grub')
|
||||||
|
if not os.path.exists (f'{MOUNTDISK}/boot/grub/menu.lst'):
|
||||||
|
os.makedirs (f'/{MOUNTDISK}/boot/grub', exist_ok=True)
|
||||||
|
open (f'/{MOUNTDISK}/boot/grub/menu.lst', 'w').close()
|
||||||
|
GRUBDISK = int (disk) - 1
|
||||||
|
with open (f'/{MOUNTDISK}/boot/grub/menu.lst', 'w') as fd:
|
||||||
|
fd.write ('##NO-TOCAR-ESTA-LINEA MBR\n')
|
||||||
|
fd.write ('timeout 0\n')
|
||||||
|
fd.write ('title MBR\n')
|
||||||
|
fd.write (f'root (hd{GRUBDISK},0)\n')
|
||||||
|
fd.write (f'chainloader (hd{GRUBDISK},0)+1\n')
|
||||||
|
fd.write ('boot\n')
|
||||||
|
fd.write ('EOT\n')
|
||||||
|
fd.write ('\n')
|
||||||
|
|
Loading…
Reference in New Issue