summaryrefslogtreecommitdiff
path: root/python/vyos/system
diff options
context:
space:
mode:
Diffstat (limited to 'python/vyos/system')
-rw-r--r--python/vyos/system/compat.py22
-rw-r--r--python/vyos/system/grub.py14
2 files changed, 26 insertions, 10 deletions
diff --git a/python/vyos/system/compat.py b/python/vyos/system/compat.py
index 37b834ad6..1b487c1d2 100644
--- a/python/vyos/system/compat.py
+++ b/python/vyos/system/compat.py
@@ -198,11 +198,11 @@ def update_cfg_ver(root_dir:str = '') -> int:
return cfg_version
-def get_default(menu_entries: list, root_dir: str = '') -> Union[int, None]:
+def get_default(data: dict, root_dir: str = '') -> Union[int, None]:
"""Translate default version to menuentry index
Args:
- menu_entries (list): list of dicts of installed version boot data
+ data (dict): boot data
root_dir (str): an optional path to the root directory
Returns:
@@ -213,10 +213,22 @@ def get_default(menu_entries: list, root_dir: str = '') -> Union[int, None]:
grub_cfg_main = f'{root_dir}/{grub.GRUB_CFG_MAIN}'
+ menu_entries = data.get('versions', [])
+ console_type = data.get('console_type', 'tty')
+ console_num = data.get('console_num', '0')
image_name = image.get_default_image()
- sublist = list(filter(lambda x: x.get('version') == image_name,
- menu_entries))
+ sublist = list(filter(lambda x: (x.get('version') == image_name and
+ x.get('console_type') == console_type and
+ x.get('console_num') == console_num and
+ x.get('bootmode') == 'normal'),
+ menu_entries))
+ # legacy images added with legacy tools omitted 'ttyUSB'; if entry not
+ # available, default to initial entry of version
+ if not sublist:
+ sublist = list(filter(lambda x: x.get('version') == image_name,
+ menu_entries))
+
if sublist:
return menu_entries.index(sublist[0])
@@ -291,7 +303,7 @@ def grub_cfg_fields(root_dir: str = '') -> dict:
menu_entries = update_version_list(root_dir)
fields['versions'] = menu_entries
- default = get_default(menu_entries, root_dir)
+ default = get_default(fields, root_dir)
if default is not None:
fields['default'] = default
diff --git a/python/vyos/system/grub.py b/python/vyos/system/grub.py
index 864ed65aa..faf68c2d1 100644
--- a/python/vyos/system/grub.py
+++ b/python/vyos/system/grub.py
@@ -18,7 +18,6 @@ import platform
from pathlib import Path
from re import MULTILINE, compile as re_compile
from shutil import copy2
-from typing import Union
from uuid import uuid5, NAMESPACE_URL, UUID
from vyos.template import render
@@ -56,7 +55,7 @@ REGEX_KERNEL_CMDLINE: str = r'^BOOT_IMAGE=/(?P<boot_type>boot|live)/((?P<image_v
REGEX_GRUB_BOOT_OPTS: str = r'^\s*set boot_opts="(?P<boot_opts>[^$]+)"$'
-def install(drive_path: str, boot_dir: str, efi_dir: str, id: str = 'VyOS') -> None:
+def install(drive_path: str, boot_dir: str, efi_dir: str, id: str = 'VyOS', chroot : str = "") -> None:
"""Install GRUB for both BIOS and EFI modes (hybrid boot)
Args:
@@ -65,17 +64,22 @@ def install(drive_path: str, boot_dir: str, efi_dir: str, id: str = 'VyOS') -> N
efi_dir (str): a path to '/boot/efi' directory
"""
+ if chroot:
+ chroot_cmd = f"chroot {chroot}"
+ else:
+ chroot_cmd = ""
+
efi_installation_arch = "x86_64"
if platform.machine() == "aarch64":
efi_installation_arch = "arm64"
elif platform.machine() == "x86_64":
cmd(
- f'grub-install --no-floppy --target=i386-pc \
+ f'{chroot_cmd} grub-install --no-floppy --target=i386-pc \
--boot-directory={boot_dir} {drive_path} --force'
)
cmd(
- f'grub-install --no-floppy --recheck --target={efi_installation_arch}-efi \
+ f'{chroot_cmd} grub-install --no-floppy --recheck --target={efi_installation_arch}-efi \
--force-extra-removable --boot-directory={boot_dir} \
--efi-directory={efi_dir} --bootloader-id="{id}" \
--no-uefi-secure-boot'
@@ -374,7 +378,7 @@ def create_structure(root_dir: str = '') -> None:
if not root_dir:
root_dir = disk.find_persistence()
- Path(f'{root_dir}/GRUB_DIR_VYOS_VERS').mkdir(parents=True, exist_ok=True)
+ Path(f'{root_dir}/{GRUB_DIR_VYOS_VERS}').mkdir(parents=True, exist_ok=True)
def set_console_type(console_type: str, root_dir: str = '') -> None: