summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-05-08 17:23:22 +0200
committerGitHub <noreply@github.com>2024-05-08 17:23:22 +0200
commitd7907cc7011459ecc99afe162490c4c571c0d9bb (patch)
treeb505de65647e5745e020139a5ea0cc19e3ffacbb
parent09abfce4008b906c7aeb62d29081fed26bb02a42 (diff)
parent167da5251c81e7f05bcaaed76634ba53f010c86f (diff)
downloadvyos-1x-d7907cc7011459ecc99afe162490c4c571c0d9bb.tar.gz
vyos-1x-d7907cc7011459ecc99afe162490c4c571c0d9bb.zip
Merge pull request #3429 from vyos/mergify/bp/sagitta/pr-3207
vyos.system.grub: T3664: add chroot argument to the GRUB install function (backport #3207)
-rw-r--r--python/vyos/system/grub.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/python/vyos/system/grub.py b/python/vyos/system/grub.py
index 9e5305300..0d9c1340b 100644
--- a/python/vyos/system/grub.py
+++ b/python/vyos/system/grub.py
@@ -55,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:
@@ -64,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'
@@ -457,3 +462,4 @@ def sort_inodes(dir_path: str) -> None:
for item in temp_list_new:
new_name = Path(f'{item.as_posix()[0:-4]}')
item.rename(new_name)
+