VTOYEFI: UEFI return chainloads Paravis GRUB; validate configs
This commit is contained in:
1 parent
d6ef2e2abb
commit
4e33ce0a62
1 file changed
+46
-48
@@ -1,50 +1,37 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Build VTOYEFI/grub/grbp.cfg with the Paravis return entry.
|
"""Validate the VTOYEFI GRUB configs for the Paravis flash.
|
||||||
|
|
||||||
grub.cfg is the normal Ventoy config (direct boot, UEFI and legacy) and must
|
Layout (do not change):
|
||||||
NOT contain the "return to Paravis" item. Only grbp.cfg - loaded by
|
|
||||||
grubx64_parv.efi when Ventoy is chainloaded from the Paravis menu - gets it.
|
grub.cfg direct Ventoy boot (UEFI and legacy). It must NOT contain the
|
||||||
|
UEFI "return to Paravis" branch. The legacy (MBR) return is
|
||||||
|
allowed and expected there.
|
||||||
|
|
||||||
|
grbp.cfg loaded by grubx64_parv.efi when Ventoy is chainloaded from the
|
||||||
|
Paravis menu. It must contain the full return entry:
|
||||||
|
UEFI -> chainload Paravis GRUB (grubx64.efi), legacy -> MBR.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
python3 patch_ventoy_paravis_return.py <path-to-grub/grub.cfg>
|
python3 patch_ventoy_paravis_return.py <path-to-grub/grub.cfg>
|
||||||
|
|
||||||
The script never modifies grub.cfg. If grub.cfg is already patched, it
|
The configs are maintained as files; this script only checks them and never
|
||||||
refuses to run, so a regression cannot be silently re-introduced.
|
modifies anything. Exit code 0 = OK, 1 = problem.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
FUNC = r'''function paravis_return {
|
UEFI_RETURN = 'chainloader ($pvroot)/efi/BOOT/bootx64.efi'
|
||||||
if [ "$grub_platform" = "efi" ]; then
|
UEFI_RETURN32 = 'chainloader ($pvroot)/efi/BOOT/bootia32.efi'
|
||||||
set pvroot=
|
PARAVIS_GRUB = 'chainloader ($pvroot)/efi/Paravis/Boot/grub2/grubx64.efi'
|
||||||
search --no-floppy --file --set=pvroot /efi/Paravis/Boot/grub2/grub.cfg
|
MBR_RETURN = 'chainloader (${vtoydev})+1'
|
||||||
if [ -z "$pvroot" ]; then
|
ID = '--id="paravis_return"'
|
||||||
echo "Paravis Flash not found"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
if [ "$grub_cpu" = "x86_64" ]; then
|
|
||||||
chainloader ($pvroot)/efi/BOOT/bootx64.efi
|
|
||||||
else
|
|
||||||
chainloader ($pvroot)/efi/BOOT/bootia32.efi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
chainloader (${vtoydev})+1
|
|
||||||
fi
|
|
||||||
boot
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
|
|
||||||
MENU = r'''menuentry "Возврат в главное меню Paravis Flash" --id="paravis_return" --class="vtoyret" {
|
|
||||||
paravis_return
|
|
||||||
}
|
|
||||||
|
|
||||||
set default="paravis_return"
|
def fail(msg):
|
||||||
'''
|
print('FAIL: ' + msg)
|
||||||
|
return 1
|
||||||
ANCHOR_FUNC = 'function ventoy_ext_menu {'
|
|
||||||
ANCHOR_MENU = '#special VTOY_DEFAULT_IMAGE process'
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -53,24 +40,35 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
path = sys.argv[1]
|
path = sys.argv[1]
|
||||||
text = io.open(path, encoding='utf-8', newline='').read()
|
try:
|
||||||
|
direct = io.open(path, encoding='utf-8', newline='').read()
|
||||||
|
except OSError as exc:
|
||||||
|
return fail('cannot read ' + path + ': ' + str(exc))
|
||||||
|
|
||||||
if 'function paravis_return' in text or '--id="paravis_return"' in text:
|
grbp_path = os.path.join(os.path.dirname(path), 'grbp.cfg')
|
||||||
print('grub.cfg already contains paravis_return, expected a clean source: ' + path)
|
try:
|
||||||
return 1
|
paravis = io.open(grbp_path, encoding='utf-8', newline='').read()
|
||||||
if text.count(ANCHOR_FUNC) != 1:
|
except OSError as exc:
|
||||||
print('anchor not found or not unique: ' + ANCHOR_FUNC)
|
return fail('cannot read ' + grbp_path + ': ' + str(exc))
|
||||||
return 1
|
|
||||||
if text.count(ANCHOR_MENU) != 1:
|
|
||||||
print('anchor not found or not unique: ' + ANCHOR_MENU)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
patched = text.replace(ANCHOR_FUNC, FUNC + '\n' + ANCHOR_FUNC, 1)
|
# Direct config: no UEFI return, legacy MBR return is fine.
|
||||||
patched = patched.replace(ANCHOR_MENU, MENU + '\n' + ANCHOR_MENU, 1)
|
if UEFI_RETURN in direct or UEFI_RETURN32 in direct:
|
||||||
|
return fail('grub.cfg contains the UEFI Paravis return (must be in grbp.cfg only)')
|
||||||
|
if PARAVIS_GRUB in direct:
|
||||||
|
return fail('grub.cfg contains the UEFI Paravis chainload (must be in grbp.cfg only)')
|
||||||
|
|
||||||
grbp = os.path.join(os.path.dirname(path), 'grbp.cfg')
|
# Paravis config: full return entry, UEFI chainloads Paravis GRUB directly
|
||||||
io.open(grbp, 'w', encoding='utf-8', newline='').write(patched)
|
# (not the shim - loading the shim a second time fails with SHIM_LOCK).
|
||||||
print('written: ' + grbp)
|
if ID not in paravis:
|
||||||
|
return fail('grbp.cfg has no paravis_return menu entry')
|
||||||
|
if PARAVIS_GRUB not in paravis:
|
||||||
|
return fail('grbp.cfg does not chainload the Paravis GRUB (grubx64.efi)')
|
||||||
|
if MBR_RETURN not in paravis:
|
||||||
|
return fail('grbp.cfg has no legacy MBR return')
|
||||||
|
if UEFI_RETURN in paravis or UEFI_RETURN32 in paravis:
|
||||||
|
return fail('grbp.cfg still chainloads the shim (bootx64.efi); use grubx64.efi')
|
||||||
|
|
||||||
|
print('OK: grub.cfg = direct boot, grbp.cfg = Paravis return (UEFI grubx64.efi + legacy MBR)')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user