Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Use kernel-core again to get modules.builtin and modules.builtin.modinfo
Browse files Browse the repository at this point in the history
depmod complains if those files are missing, and it seems we really need them to
correctly load all modules. This means that we need both files. Usually,
kernel-core will be installed if kernel-modules-core is, so it's not such a big
issue.
  • Loading branch information
keszybz committed Oct 11, 2023
1 parent c88cb81 commit 838184d
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions mkosi.finalize
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ def kernel_core_skip_file(path):
return any(fnmatch.fnmatch(path, pat)
for pat in patterns)

def copy_in_modules_from_rpmls(root, kver, modules_rpm):
rpm = f'{modules_rpm}-{kver}'
def copy_in_modules_from_rpmls(root, kver, rpms):

Check warning

Code scanning / vcs-diff-lint

copy_in_modules_from_rpmls: Unused argument 'kver' Warning

copy_in_modules_from_rpmls: Unused argument 'kver'
try:
out = subprocess.check_output(['rpm', '-ql', rpm], text=True)
out = subprocess.check_output(['rpm', '-ql', *rpms], text=True)
except (FileNotFoundError, subprocess.CalledProcessError) as e:
print(f'Cannot query file list of {rpm}:', e)
print(f"rpm -ql {' '.join(rpms)} failed:", e)
return False

files = out.splitlines()
Expand All @@ -70,7 +69,7 @@ def copy_in_modules_from_rpmls(root, kver, modules_rpm):
shutil.copy2(file, dest, follow_symlinks=False)
installed += 1

print(f'Installed {installed}/{installed + skipped} files from {rpm}')
print(f"Installed {installed}/{installed + skipped} files from {' '.join(rpms)}")
return True

def copy_in_modules_from_fs(root, kver):
Expand All @@ -84,40 +83,47 @@ def copy_in_modules_from_fs(root, kver):
print(f'Copied files from {source}')
return True

def copy_in_modules_from_cpio(root, kver, modules_rpm):
def copy_in_modules_from_cpio(root, kver, rpms):

Check warning

Code scanning / vcs-diff-lint

copy_in_modules_from_cpio: Unused argument 'kver' Warning

copy_in_modules_from_cpio: Unused argument 'kver'
file_filter = ['--nonmatching',
'./lib/modules/*/bls.conf', # a grub abomination with $grub_variables
'./lib/modules/*/vmlinuz']

path = pathlib.Path(sys.argv[0]).parent
file = path / f'{modules_rpm}-{kver}.rpm'

if not file.exists():
print(f'{file} not found, downloading.')
for rpm in rpms:
file = path / f'{rpm}.rpm'

if not file.exists():
print(f'{file} not found, downloading.')

subprocess.run(['dnf', 'download', f'--downloaddir={file.parent}',
file.with_suffix('').name],
check=True)

subprocess.run(['dnf', 'download', f'--downloaddir={file.parent}',
file.with_suffix('').name],
check=True)
with subprocess.Popen(['rpm2cpio', file], stdout=subprocess.PIPE) as archive:
subprocess.run(['cpio', '-i', '--make-directories', '--quiet',
'-D', root,
*file_filter],
stdin=archive.stdout,
check=True)

with subprocess.Popen(['rpm2cpio', file], stdout=subprocess.PIPE) as archive:
subprocess.run(['cpio', '-i', '--make-directories', '--quiet', '-D', root, *file_filter],
stdin=archive.stdout,
check=True)
print(f'Unpacked files from {file}')

print(f'Unpacked files from {file}')
return True

def copy_in_modules_kver(root, kver):
print(f'Installing modules for kernel {kver}')

res = subprocess.check_output(['rpm', '--eval', f'%[v"{kver}" >= v"6.2.0"]'],
text=True)
good = res.strip() == '1'
modules_rpm = 'kernel-modules-core' if good else 'kernel-core'
have_split = res.strip() == '1'
# kernel-core contains modules.builtin and modules.builtin.modinfo, so we need in too :(
rpms = [f'kernel-core-{kver}']
if have_split:
rpms += [f'kernel-modules-core-{kver}']

copy_in_modules_from_rpmls(root, kver, modules_rpm) or \
copy_in_modules_from_rpmls(root, kver, rpms) or \

Check warning

Code scanning / vcs-diff-lint

copy_in_modules_kver: Expression "copy_in_modules_from_rpmls(root, kver, rpms) or copy_in_modules_from_fs(root, kver) or copy_in_modules_from_cpio(root, kver, rpms)" is assigned to nothing Warning

copy_in_modules_kver: Expression "copy_in_modules_from_rpmls(root, kver, rpms) or copy_in_modules_from_fs(root, kver) or copy_in_modules_from_cpio(root, kver, rpms)" is assigned to nothing
copy_in_modules_from_fs(root, kver) or \
copy_in_modules_from_cpio(root, kver, modules_rpm)
copy_in_modules_from_cpio(root, kver, rpms)

subprocess.run(['depmod', '-a', '-w', '-b', root, kver], check=True)

Expand Down

0 comments on commit 838184d

Please sign in to comment.