Commit 52406bf3 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Merge branch 'nkupdates' into 'master'

Generate grub.cfg

See merge request idms-linux-rolling/projects/idms-linux-installer!5
parents 434fe4d6 e4ee8681
......@@ -45,8 +45,6 @@ class ConfigSystemGrub(Plugin):
if 'lvm2' in ili_state.base_packages:
kwargs['lvm'] = True
sysgrub.configure(ili_state.target_root)
# Loop with each disk we must install an MBR on
for device in ili_state.boot_mbrs:
ili_state.output_callback(f'Installing grub MBR on {device}')
......@@ -56,3 +54,6 @@ class ConfigSystemGrub(Plugin):
if ili_state.fstab['efi']:
ili_state.output_callback('Installing grub EFI in %s' % ili_state.fstab['efi']['mount_point'])
sysgrub.install_efi(ili_state.target_root, ili_state.fstab['efi']['mount_point'], ili_state.output_callback)
# We configure grub after the installation becaues this is when the /boot/grub dir exists
sysgrub.configure(ili_state.target_root, ili_state.output_callback)
......@@ -17,6 +17,7 @@
import os
import re
from typing import Optional
from .asyncsubprocess import AsyncSubprocess, OutputCallback
......@@ -27,14 +28,20 @@ class SysGrub:
def __init__(self):
"""Initialize our class."""
def configure(self, system_path: str, **kwargs):
def configure(self, system_path: str, output_callback: Optional[OutputCallback] = None, **kwargs):
"""Configure grub."""
sys_grub_conf = f'{system_path}/etc/default/grub'
sys_grub_conf_new = f'{sys_grub_conf}.new'
sys_grub_conf = '/boot/grub/grub.cfg'
sys_default_grub = f'{system_path}/etc/default/grub'
sys_default_grub_new = f'{sys_default_grub}.new'
# If we didn't get an output_callback, set it to our own class method
if not output_callback:
output_callback = self._default_output_callback
# Open the config files and process
with open(sys_grub_conf, 'r') as conf_file, open(sys_grub_conf_new, 'w') as conf_file_new:
with open(sys_default_grub, 'r') as conf_file, open(sys_default_grub_new, 'w') as conf_file_new:
# Loop with lines
for line in conf_file:
# Check if we can pull out the modules
......@@ -59,7 +66,16 @@ class SysGrub:
conf_file_new.close()
# Move new file ontop of old one
os.replace(sys_grub_conf_new, sys_grub_conf)
os.replace(sys_default_grub_new, sys_default_grub)
# Run grub-mkconfig
proc = AsyncSubprocess(['arch-chroot', system_path, 'grub-mkconfig', '-o', sys_grub_conf],
output_callback=output_callback)
proc.run()
# Raise an exception if we didn't get a positive response back
if proc.retcode != 0:
raise OSError(f'Failed to run grub-mkconfig on the target system, return code {proc.retcode}')
def install_mbr(self, system_path: str, device: str, output_callback: OutputCallback = None):
"""Install grub on the MBR."""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment