Skip to content

Commit

Permalink
also find std kernels on ESP/EFI/Gentoo
Browse files Browse the repository at this point in the history
These kernels are installed by installkernel[efistub] for efi stub
booting (not UKI booting, UKIs are in ESP/EFI/Linux)

Closes: #28
Signed-off-by: Andrew Ammerlaan <[email protected]>
  • Loading branch information
Nowa-Ammerlaan committed Apr 8, 2024
1 parent 5a840b6 commit 0bd946d
Showing 1 changed file with 53 additions and 48 deletions.
101 changes: 53 additions & 48 deletions ecleankernel/layout/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class StdLayout(ModuleDirLayout):
'.gz',
'.lz',
'.xz',

# efistub
'.efi',
]

def find_kernels(self,
Expand All @@ -63,54 +66,56 @@ def find_kernels(self,
# collect from /boot
kernels: typing.Dict[str, typing.Dict[str, Kernel]] = {}
other_files: typing.List[typing.Tuple[GenericFile, str]] = []
boot_directory = self.root / 'boot'
try:
diter = os.listdir(boot_directory)
except FileNotFoundError:
pass
else:
for fn in diter:
# skip hidden and GRUB signature files
if fn.startswith('.') or fn.endswith('.sig'):
continue
path = boot_directory / fn
if path.is_symlink() or not path.is_file():
continue
# skip unversioned files
ver = fn.partition('-')[2]
if not ver:
continue

# strip suffix from filename to get the correct version
for suffix in self.suffixes:
if ver.endswith(suffix):
ver = ver[:-len(suffix)]
break
elif ver.endswith(suffix + '.old'):
ver = ver[:-len(suffix)-4] + '.old'

# try recognizing kernel image via magic
try:
kobj = KernelImage(path)
except UnrecognizedKernelError:
# fall back to filename
for ftype, prefix in self.prefixes:
if ftype not in exclusions:
if fn.startswith(prefix):
other_files.append(
(GenericFile(path, ftype), ver))
break
continue

# the following is done only for kernel images
assert isinstance(kobj, KernelImage)
kg = kernels.setdefault(ver, {})
k = kg.setdefault(kobj.internal_version, Kernel(ver))
k.all_files.append(kobj)

# associate the module directory
k.all_files.extend(
module_dict.get(kobj.internal_version, []))
for boot_directory in self.root / 'boot', self.root / 'boot/EFI/EFI/Gentoo', \
self.root / 'boot/efi/EFI/Gentoo', self.root / 'boot/EFI/Gentoo', \
self.root / 'efi/EFI/Gentoo':
try:
diter = os.listdir(boot_directory)
except FileNotFoundError:
continue
else:
for fn in diter:
# skip hidden and GRUB signature files
if fn.startswith('.') or fn.endswith('.sig'):
continue
path = boot_directory / fn
if path.is_symlink() or not path.is_file():
continue
# skip unversioned files
ver = fn.partition('-')[2]
if not ver:
continue

# strip suffix from filename to get the correct version
for suffix in self.suffixes:
if ver.endswith(suffix):
ver = ver[:-len(suffix)]
break
elif ver.endswith(suffix + '.old'):
ver = ver[:-len(suffix)-4] + '.old'

# try recognizing kernel image via magic
try:
kobj = KernelImage(path)
except UnrecognizedKernelError:
# fall back to filename
for ftype, prefix in self.prefixes:
if ftype not in exclusions:
if fn.startswith(prefix):
other_files.append(
(GenericFile(path, ftype), ver))
break
continue

# the following is done only for kernel images
assert isinstance(kobj, KernelImage)
kg = kernels.setdefault(ver, {})
k = kg.setdefault(kobj.internal_version, Kernel(ver))
k.all_files.append(kobj)

# associate the module directory
k.all_files.extend(
module_dict.get(kobj.internal_version, []))

# merge other files into kernel groups
for fobj, ver in other_files:
Expand Down

0 comments on commit 0bd946d

Please sign in to comment.