Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions kernel-install/50-mkosi-initrd.install
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ case "$COMMAND" in
BUILD_DIR=$(mktemp -d -p /var/tmp)
(
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && set -x
cd "$BUILD_DIR"

mkosi --default /usr/lib/mkosi-initrd/fedora.mkosi \
mkosi --include=/usr/lib/mkosi-initrd/mkosi.conf \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just specify /usr/lib/mkosi-initrd here and it will pick up the finalize script automatically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to be explicit.

--workspace-dir="$BUILD_DIR" \
--finalize-script=/usr/lib/mkosi-initrd/mkosi.finalize \
--image-version="$KERNEL_VERSION" \
--environment=KERNEL_VERSION="$KERNEL_VERSION" \
-o "${KERNEL_INSTALL_STAGING_AREA}/initrd"
--image-version="$KERNEL_VERSION" \
--environment="KERNEL_VERSION=$KERNEL_VERSION" \
-O "${KERNEL_INSTALL_STAGING_AREA}" \
-o initrd

rm "${KERNEL_INSTALL_STAGING_AREA}/initrd"
mv -v "${KERNEL_INSTALL_STAGING_AREA}"/initrd_*.cpio.zst \
"${KERNEL_INSTALL_STAGING_AREA}/initrd"

rm -rf "$BUILD_DIR"
)
;;
Expand Down
18 changes: 8 additions & 10 deletions fedora.mkosi → mkosi.conf
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

[Distribution]
# Distribution=fedora
# Release=34

[Output]
ImageId=initrd
Format=cpio
ManifestFormat=
Compress=zstd

# This will create the cache and output directories if they aren't already in place
Cache=mkosi.cache
CompressOutput=yes # zstd

[Content]
BasePackages=conditional
Bootable=no
MakeInitrd=yes

Packages=
systemd # sine qua non
systemd-udev
Expand All @@ -38,7 +33,7 @@ Packages=
tpm2-tss

RemovePackages=
# Various packages pull shadow-utils to create users
# Various packages pull in shadow-utils to create users
shadow-utils

# Dropping those will require getting rid of deps in systemd and possibly other packages
Expand All @@ -50,3 +45,6 @@ RemoveFiles=
/usr/lib/systemd/catalog
/etc/udev/hwdb.d
/usr/lib/udev/hwdb.d

# this is not needed by anything updated in the last 20 years
/etc/services
1 change: 0 additions & 1 deletion mkosi.default

This file was deleted.

58 changes: 32 additions & 26 deletions mkosi.finalize
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later

# pylint: disable=missing-function-docstring,missing-module-docstring,line-too-long

import ast
import fnmatch
import functools
Expand Down Expand Up @@ -48,12 +50,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, rpms):
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 +71,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 +85,48 @@ 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, rpms):
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_fs(root, kver) or \
copy_in_modules_from_cpio(root, kver, modules_rpm)
if not (copy_in_modules_from_rpmls(root, rpms) or
copy_in_modules_from_fs(root, kver) or
copy_in_modules_from_cpio(root, rpms)):
raise Exception(f'Failed to copy modules for kernel {kver}')

Check warning

Code scanning / vcs-diff-lint

copy_in_modules_kver: Raising too general exception: Exception

copy_in_modules_kver: Raising too general exception: Exception

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

Expand Down Expand Up @@ -301,9 +310,6 @@ def do_sysext(root, sysext_name):
remove_non_sysext_files(root)

def main(argv):
if argv[1] != 'final':
sys.exit(0)

root = buildroot()

sysext = os.getenv('SYSEXT')
Expand Down