From 59b702047ddb649e2bc0b987b3c0b05cea757247 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 6 Mar 2025 10:17:10 +0100 Subject: [PATCH] refs #1622 add ogGrub4dosInstallMbr --- ogclient/lib/python3/BootLib.py | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ogclient/lib/python3/BootLib.py b/ogclient/lib/python3/BootLib.py index de349a1..8eb00b2 100644 --- a/ogclient/lib/python3/BootLib.py +++ b/ogclient/lib/python3/BootLib.py @@ -1285,12 +1285,12 @@ def ogBootLoaderSetTimeOut (disk, par, timeout): def ogGrub4dosInstallMbr (disk, par): #Controlar existencia de disco y particion - DEVICE = DiskLib.ogDiskToDev (disk) - if not DEVICE: + device = DiskLib.ogDiskToDev (disk) + if not device: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, '') return None - MOUNTDISK = FileSystemLib.ogMount (disk, par) - if not MOUNTDISK: + 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 @@ -1307,29 +1307,29 @@ def ogGrub4dosInstallMbr (disk, par): 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') + 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) + subprocess.run ([f'{bindir}/bootlace64.com', device], capture_output=True) #copiar grld a la particion - shutil.copy2 (f'{BINDIR}/grldr', MOUNTDISK) + 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: + 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 (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')