grub: move get_grub_boot_params() into grub.py

Move get_grub_boot_params() into the file related to all the grub
configuration.
master
Alejandro Sirgo Rica 2024-10-22 13:41:45 +02:00
parent 373c1b2a72
commit fb707cef0b
3 changed files with 19 additions and 16 deletions

View File

@ -11,22 +11,6 @@ import os
from src.log import OgError
def get_grub_boot_params(mountpoint, device):
grub_conf = f'{mountpoint}/etc/default/grub'
res = []
with open(grub_conf, 'r') as f:
for line in f:
if line.find('=') == -1:
continue
key, value = line.split('=', 1)
if key == 'GRUB_CMDLINE_LINUX' or key == 'GRUB_CMDLINE_LINUX_DEFAULT':
value = value.replace('\n', '')
value = value.strip('"')
res.append(value)
res.append(f'root={device}')
return " ".join(res)
def get_vmlinuz_path(mountpoint):
linuz_dir = os.path.join(mountpoint, 'boot')
target_file = None

View File

@ -13,6 +13,7 @@ import subprocess
from src.utils.probe import OSFamily, get_os_family, get_linux_distro_id, os_probe
from src.utils.disk import get_partition_device, get_efi_partition
from src.utils.grub import get_grub_boot_params
from src.utils.bios import *
from src.utils.uefi import *
from src.utils.fs import *

View File

@ -110,6 +110,24 @@ class MenuEntry:
entry_name = entry_name.replace('!', r'\!')
return entry_name
def get_grub_boot_params(mountpoint, device):
grub_conf = f'{mountpoint}/etc/default/grub'
res = []
with open(grub_conf, 'r') as f:
for line in f:
if line.find('=') == -1:
continue
key, value = line.split('=', 1)
if key == 'GRUB_CMDLINE_LINUX' or key == 'GRUB_CMDLINE_LINUX_DEFAULT':
value = value.replace('\n', '')
value = value.strip('"')
res.append(value)
res.append(f'root={device}')
return " ".join(res)
def _get_linux_data(disk_num, part_num, mountpoint):
os_entry = {}
os_entry['name'] = f'{os_probe(mountpoint)} ({disk_num}, {part_num})'