From 373c1b2a724a3855f93d9cc4b48d0c33310a482c Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Fri, 11 Oct 2024 12:15:09 +0200 Subject: grub: replace legacy grub install scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translate old legacy grub scripts into grub.py Implement ogGrubInstallMbr as install_main_grub() and ogGrubInstallPartition as install_linux_grub(). Add grub configuration file generator through the classes GrubConfig and MenuEntry. Ensure EFI tree structure compatibility with legacy code. The structure of the created folders in the ESP is non-standard, efi binaries are usually located in the folder below the EFI/ directory. Structure used by ogClient: EFI/ ├── grub/ │ └── Boot/ │ ├── BOOTX64.CSV │ ├── grub.cfg │ ├── mmx64.efi │ ├── shimx64.efi │ ├── BOOTX64.EFI │ ├── grubx64.efi │ └── ogloader.efi ... The function _mangle_efi_folder handles the folder structure after grub-install to comply with the location expected by ogLive. install_linux_grub() installs a grub local to each Linux install to enable chainloading, each grub is located in EFI/Part-xx-yy/ in UEFI. The local linux BIOS grub in legacy scripts is unreliable, grub-install reports a failure during the install process. install_main_grub() installs a global grub in EFI/grub/ to show a grub menu when the pxe boot fails. The global grub contains entries to every installed os. No global grub is installed for BIOS systems, a Boot partition would be required to store the grub configuration. --- src/utils/postinstall.py | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) (limited to 'src/utils/postinstall.py') diff --git a/src/utils/postinstall.py b/src/utils/postinstall.py index 221da81..90b8cc6 100644 --- a/src/utils/postinstall.py +++ b/src/utils/postinstall.py @@ -12,6 +12,7 @@ import logging import hivex import shlex from src.log import OgError +from src.utils.grub import install_main_grub, install_linux_grub from src.utils.bcd import update_bcd from src.utils.probe import * from src.utils.disk import * @@ -152,19 +153,6 @@ def configure_mbr_boot_sector(disk, partition): logging.warning(f'{cmd_configure} returned non-zero exit status {proc.returncode}') -def configure_grub_in_mbr(disk, partition): - cmd_configure = f"ogGrubInstallMbr {disk} {partition} TRUE" - - proc = subprocess.run(cmd_configure, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - encoding='utf-8', - shell=True, - check=True) - if proc.returncode != 0: - logging.warning(f'{cmd_configure} returned non-zero exit status {proc.returncode}') - - def configure_fstab(disk, partition): logging.info(f'Configuring /etc/fstab') device = get_partition_device(disk, partition) @@ -178,31 +166,17 @@ def configure_fstab(disk, partition): finally: umount(mountpoint) - -def install_grub(disk, partition): - cmd_configure = f"ogGrubInstallPartition {disk} {partition}" - - proc = subprocess.run(cmd_configure, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - encoding='utf-8', - shell=True, - check=True) - if proc.returncode != 0: - logging.warning(f'{cmd_configure} returned non-zero exit status {proc.returncode}') - - def configure_os_linux(disk, partition): hostname = gethostname() set_linux_hostname(disk, partition, hostname) configure_fstab(disk, partition) + install_linux_grub(disk, partition) + if is_uefi_supported(): _, _, esp_part_number = get_efi_partition(disk, enforce_gpt=True) - configure_grub_in_mbr(disk, esp_part_number) - - install_grub(disk, partition) + install_main_grub() def configure_os_windows(disk, partition): @@ -213,7 +187,7 @@ def configure_os_windows(disk, partition): restore_windows_efi_bootloader(disk, partition) _, _, esp_part_number = get_efi_partition(disk, enforce_gpt=True) - configure_grub_in_mbr(disk, esp_part_number) + install_main_grub() else: configure_mbr_boot_sector(disk, partition) -- cgit v1.2.3-18-g5258