import dataclasses
import datetime
import hashlib
+import io
import itertools
import json
import logging
read_env_file,
read_os_release,
resource_path,
+ round_up,
scopedenv,
try_import,
umask,
return kmods
+def join_initrds(initrds: Sequence[Path], output: Path) -> Path:
+ assert initrds
+
+ if len(initrds) == 1:
+ copy_tree(initrds[0], output)
+ return output
+
+ seq = io.BytesIO()
+ for p in initrds:
+ initrd = p.read_bytes()
+ n = len(initrd)
+ padding = b'\0' * (round_up(n, 4) - n) # pad to 32 bit alignment
+ seq.write(initrd)
+ seq.write(padding)
+
+ output.write_bytes(seq.getbuffer())
+ return output
+
+
def python_binary(config: MkosiConfig) -> str:
# If there's no tools tree, prefer the interpreter from MKOSI_INTERPRETER. If there is a tools
# tree, just use the default python3 interpreter.
break
+def copy_initrd(state: MkosiState) -> None:
+ if (state.staging / state.config.output_split_initrd).exists():
+ return
+
+ if state.config.bootable == ConfigFeature.disabled:
+ return
+
+ if state.config.output_format not in (OutputFormat.disk, OutputFormat.directory):
+ return
+
+ for kver, _ in gen_kernel_images(state):
+ microcode = build_microcode_initrd(state)
+ initrds = [microcode] if microcode else []
+ initrds += state.config.initrds or [build_initrd(state)]
+ if state.config.kernel_modules_initrd:
+ kver = next(gen_kernel_images(state))[0]
+ initrds += [build_kernel_modules_initrd(state, kver)]
+ join_initrds(initrds, state.staging / state.config.output_split_initrd)
+ break
+
+
def hash_file(of: TextIO, path: Path) -> None:
bs = 16 * 1024**2
h = hashlib.sha256()
make_disk(state, split=True, msg="Extracting partitions")
copy_vmlinuz(state)
+ copy_initrd(state)
if state.config.output_format == OutputFormat.tar:
make_tar(state.root, state.staging / state.config.output_with_format)