diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d88470..747d17b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.22.4] - 2025-07-01 + +### Changed + +- Do copy grub.cfg :) and clean it up on boot +- Remove warning about /dev/loop0 +- Comment unused code out + ## [0.22.3] - 2025-06-27 ### Changed diff --git a/ogclient/etc/preinit/cleanesp.sh b/ogclient/etc/preinit/cleanesp.sh new file mode 100755 index 0000000..0cef989 --- /dev/null +++ b/ogclient/etc/preinit/cleanesp.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +F=/opt/opengnsys/functions + +## BootLib.bootOs() makes a copy of grub.cfg in /boot/grub within the ESP +## clean it up +if $F/ogIsEfiActive; then + ESP=$($F/ogGetEsp) + MNTPT=$($F/ogMount $ESP) + rm -f $MNTPT/boot/grub/grub.cfg + $F/ogUnmount $ESP +fi diff --git a/ogclient/etc/preinit/default.sh b/ogclient/etc/preinit/default.sh index 5c2623b..a012b32 100755 --- a/ogclient/etc/preinit/default.sh +++ b/ogclient/etc/preinit/default.sh @@ -5,7 +5,7 @@ set -a source /opt/opengnsys/etc/preinit/loadenviron.sh # Scripts de inicio. -for f in fileslinks loadmodules metadevs mountrepo poweroff otherservices; do +for f in cleanesp fileslinks loadmodules metadevs mountrepo poweroff otherservices; do source $OGETC/preinit/$f.sh done unset f diff --git a/ogclient/lib/python3/BootLib.py b/ogclient/lib/python3/BootLib.py index 5660585..cbc21e7 100644 --- a/ogclient/lib/python3/BootLib.py +++ b/ogclient/lib/python3/BootLib.py @@ -126,6 +126,14 @@ def ogBoot (disk, par, nvramperm=False, params=''): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{esp} Boot loader') return None + esp_dev = DiskLib.ogDiskToDev (efidisk, efipart) + esp_mntdir = esp_dev.replace ('dev', 'mnt') + os.makedirs (f'{esp_mntdir}/boot/grub', exist_ok=True) + grub_cfg_src = f'{esp_mntdir}/EFI/{bootlabel}/Boot/grub.cfg' + if not os.path.exists (grub_cfg_src): + grub_cfg_src = f'{esp_mntdir}/boot/grubMBR/boot/grub/grub.cfg' + shutil.copy2 (grub_cfg_src, f'{esp_mntdir}/boot/grub/grub.cfg') + # Crear orden de arranque (con unos valores por defecto). UEFILib.ogNvramAddEntry (bootlabel, f'/EFI/{bootlabel}/Boot/{bootloader}', nvramperm) # Marcar próximo arranque y reiniciar. @@ -156,6 +164,14 @@ def ogBoot (disk, par, nvramperm=False, params=''): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTOS, f'{disk} {par} ({type}, EFI)') return None + esp_dev = DiskLib.ogDiskToDev (efidisk, efipart) + esp_mntdir = esp_dev.replace ('dev', 'mnt') + os.makedirs (f'{esp_mntdir}/boot/grub', exist_ok=True) + grub_cfg_src = f'{esp_mntdir}/EFI/{bootlabel}/Boot/grub.cfg' + if not os.path.exists (grub_cfg_src): + grub_cfg_src = f'{esp_mntdir}/boot/grubMBR/boot/grub/grub.cfg' + shutil.copy2 (grub_cfg_src, f'{esp_mntdir}/boot/grub/grub.cfg') + # Crear orden de arranque (con unos valores por defecto). l = re.sub ('^.*EFI(.*)$', r'\1', loader) UEFILib.ogNvramAddEntry (bootlabel, '/EFI'+l, nvramperm) diff --git a/ogclient/lib/python3/DiskLib.py b/ogclient/lib/python3/DiskLib.py index 4a4f344..24138a7 100644 --- a/ogclient/lib/python3/DiskLib.py +++ b/ogclient/lib/python3/DiskLib.py @@ -400,7 +400,8 @@ def ogDevToDisk(arg_dev): # Error si no es fichero de bloques o directorio (para LVM). m = os.stat (DEV, follow_symlinks=True).st_mode if not stat.S_ISBLK (m) and not stat.S_ISDIR (m): - SystemLib.ogRaiseError([], ogGlobals.OG_ERR_NOTFOUND, arg_dev) + if '/dev/loop' != DEV[0:9]: + SystemLib.ogRaiseError([], ogGlobals.OG_ERR_NOTFOUND, arg_dev) return # Buscar en fichero de caché de discos. @@ -424,7 +425,8 @@ def ogDevToDisk(arg_dev): return f"{n} {DEV[len(d) + len(NVME_PREFIX):]}" n += 1 - SystemLib.ogRaiseError([], ogGlobals.OG_ERR_NOTFOUND, arg_dev) + if '/dev/loop' != DEV[0:9]: + SystemLib.ogRaiseError([], ogGlobals.OG_ERR_NOTFOUND, arg_dev) return def _getAllDisks(): diff --git a/ogclient/lib/python3/FileLib.py b/ogclient/lib/python3/FileLib.py index 301c618..a315740 100644 --- a/ogclient/lib/python3/FileLib.py +++ b/ogclient/lib/python3/FileLib.py @@ -215,7 +215,7 @@ def ogCopyFile (src, dst): return # Copiar fichero (para evitar problemas de comunicaciones las copias se hacen con rsync en vez de cp). - result = subprocess.run(["rsync", "--progress", "--inplace", "-avh", SOURCE, TARGET], text=True) ## they want the output + result = subprocess.run(["rsync", "--progress", "--inplace", "-avh", SOURCE, TARGET], text=True) return not result.returncode ## negate shell result diff --git a/ogclient/lib/python3/NetLib.py b/ogclient/lib/python3/NetLib.py index 438d72d..0223a18 100644 --- a/ogclient/lib/python3/NetLib.py +++ b/ogclient/lib/python3/NetLib.py @@ -217,15 +217,15 @@ def ogGetMacAddress(): #@return str_interface - interfaz de red #@note Usa las variables utilizadas por el initrd "/etc/net-ethX.conf #*/ ## -def ogGetNetInterface(): - if len(sys.argv) >= 2 and sys.argv[1] == "help": - SystemLib.ogHelp("ogGetNetInterface", "ogGetNetInterface", "ogGetNetInterface => eth0") - return - - if "DEVICE" in os.environ: - print(os.environ["DEVICE"]) - - return 0 +#def ogGetNetInterface(): +# if len(sys.argv) >= 2 and sys.argv[1] == "help": +# SystemLib.ogHelp("ogGetNetInterface", "ogGetNetInterface", "ogGetNetInterface => eth0") +# return +# +# if "DEVICE" in os.environ: +# print(os.environ["DEVICE"]) +# +# return 0 #/** # ogGetRepoIp @@ -277,22 +277,22 @@ def ogGetServerPort(): #@note repo = { REPO, CACHE } REPO por defecto #@exception OG_ERR_FORMAT formato incorrecto. #*/ -def ogMakeGroupDir(): - REPO = "" - DIR = "" - GROUP = "" - - if len(sys.argv) < 2: - SystemLib.ogHelp("ogMakeGroupDir", "ogMakeGroupDir str_repo", "ogMakeGroupDir", "ogMakeGroupDir REPO") - return - - if len(sys.argv) == 1: - REPO = "REPO" - else: - REPO = sys.argv[1] - - DIR = FileLib.ogGetPath(REPO, "/groups/" + ogGetGroupName(), stderr=subprocess.DEVNULL) - if DIR: - subprocess.run(["mkdir", "-p", DIR], stderr=subprocess.DEVNULL) - - return 0 +#def ogMakeGroupDir(): +# REPO = "" +# DIR = "" +# GROUP = "" +# +# if len(sys.argv) < 2: +# SystemLib.ogHelp("ogMakeGroupDir", "ogMakeGroupDir str_repo", "ogMakeGroupDir", "ogMakeGroupDir REPO") +# return +# +# if len(sys.argv) == 1: +# REPO = "REPO" +# else: +# REPO = sys.argv[1] +# +# DIR = FileLib.ogGetPath(REPO, "/groups/" + ogGetGroupName(), stderr=subprocess.DEVNULL) +# if DIR: +# subprocess.run(["mkdir", "-p", DIR], stderr=subprocess.DEVNULL) +# +# return 0 diff --git a/ogclient/lib/python3/UEFILib.py b/ogclient/lib/python3/UEFILib.py index f45d7d2..cd7e004 100644 --- a/ogclient/lib/python3/UEFILib.py +++ b/ogclient/lib/python3/UEFILib.py @@ -500,6 +500,7 @@ def ogNvramSetNext (entry): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, f'more than one entry found') return + SystemLib.ogEcho ([], 'info', f'setting "{numentries[0]}" as next entry in NVRAM') subprocess.run (['efibootmgr', '-n', numentries[0]], capture_output=True, text=True) #/** diff --git a/ogclient/scripts/restoreImage.py b/ogclient/scripts/restoreImage.py index 5e62c79..70ebc38 100755 --- a/ogclient/scripts/restoreImage.py +++ b/ogclient/scripts/restoreImage.py @@ -47,7 +47,6 @@ if SystemLib.ogGetCaller() not in ['deployImage', 'restoreImageCustom']: SystemLib.ogEcho (['log', 'session'], None, f'[1] {ogGlobals.lang.MSG_SCRIPTS_START} {prog} ({sys.argv})') # Procesar parámetros de entrada -print (f'argv ({sys.argv}) len ({len (sys.argv)})') if len (sys.argv) < 5: SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {prog} REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]') sys.exit (1) diff --git a/ogclient/scripts/updateCache.py b/ogclient/scripts/updateCache.py index 78e26b2..c990c9c 100755 --- a/ogclient/scripts/updateCache.py +++ b/ogclient/scripts/updateCache.py @@ -37,7 +37,6 @@ import ProtocolLib import FileSystemLib prog = os.path.basename (sys.argv[0]) -print (f'argv ({sys.argv}) len ({len (sys.argv)})') if len (sys.argv) < 3: SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {prog} str_REPO _str_Relative_Path_OGIMG_with_/ PROTOCOLO OPCIONES_PROTOCOLO OPCIONES_UPDATECACHE') sys.exit (1)