Skip to content

Commit

Permalink
bootloader: consider GRUB_CFG as location for grub config
Browse files Browse the repository at this point in the history
sys-kernel/installkernel[grub] supports setting GRUB_CFG in the environment to
update a grub.cfg in a non-standard location. Specifically this is useful with
sys-boot/grub[secureboot] where the built grub efi executable loads the
grub.cfg from the same directory it is in.

Recognize the same environment variable here so we don't accidentally update
the wrong config.

Signed-off-by: Andrew Ammerlaan <[email protected]>
  • Loading branch information
Nowa-Ammerlaan committed Oct 26, 2024
1 parent 55aa5e8 commit ac038fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ecleankernel/bootloader/grub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import logging
import os.path
import os
import typing

from ecleankernel.bootloader.lilo import LILO
Expand All @@ -11,7 +11,7 @@
class GRUB(LILO):
name = 'grub'
kernel_re = r'^\s*(kernel|module)\s*(\([^)]+\))?(?P<path>\S+)'
def_path = ('/boot/grub/menu.lst', '/boot/grub/grub.conf')
def_path = (os.getenv("GRUB_CFG"), '/boot/grub/menu.lst', '/boot/grub/grub.conf')

def _get_kernels(self,
content: str
Expand Down
3 changes: 2 additions & 1 deletion ecleankernel/bootloader/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import logging
import os
import subprocess
import typing

Expand All @@ -17,7 +18,7 @@
class GRUB2(GRUB):
name = 'grub2'
kernel_re = r'^\s*linux\s*(\([^)]+\))?(?P<path>\S+)'
def_path = ('/boot/grub/grub.cfg', '/boot/grub2/grub.cfg')
def_path = (os.getenv("GRUB_CFG"), '/boot/grub/grub.cfg', '/boot/grub2/grub.cfg')

def __init__(self) -> None:
super().__init__()
Expand Down
19 changes: 10 additions & 9 deletions ecleankernel/bootloader/lilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class LILO(Bootloader):
name = 'lilo'
kernel_re = r'^\s*image\s*=\s*(?P<path>.+)\s*$'
def_path: typing.Tuple[str, ...] = ('/etc/lilo.conf',)
def_path: typing.Tuple[typing.Union[str, None], ...] = ('/etc/lilo.conf',)

def __init__(self,
path: typing.Optional[str] = None
Expand All @@ -23,14 +23,15 @@ def __init__(self,
paths = (paths,)

for p in paths:
try:
with open(p) as f:
logging.debug(f'{p} found')
self.path = p
self._content = f.read()
break
except FileNotFoundError:
pass
if p:
try:
with open(p) as f:
logging.debug(f'{p} found')
self.path = p
self._content = f.read()
break
except FileNotFoundError:
pass
else:
raise BootloaderNotFound()

Expand Down

0 comments on commit ac038fa

Please sign in to comment.