Repository navigation
vmlinuz: Decompress zstd and LZ4 kernels without external tools - #26
Merged
Merged
Conversation
Extracting the vmlinux of a bzImage was the one place where kerf ran another program: lz4 for an LZ4 kernel, and zstd for a zstd kernel where the zstandard module was missing, which is any plain install as the module was never a dependency. A missing binary was only found out at kerf load, and its output was trusted whatever it wrote to stderr. Use the zstandard and lz4 modules instead and make them dependencies, of the wheel and of the deb and rpm packages. The kernel build compresses with lz4 -l, the legacy format, which the frame API of the lz4 module does not read. It is a magic number and then blocks of at most 8 MB, each behind its compressed size, so walk them and decompress each as a raw block. The frame format is still taken, through the frame API. The build appends the size of the vmlinux to the compressed stream. The tools complained about it and decompressed anyway; here it reads as a block that the payload has no room for, which ends the legacy format, and the frame and zstd decompressors stop at the end of their stream. The modules are imported when a kernel needs them, so that a machine without one can still run every command but the load of such a kernel, which says which module is missing. Signed-off-by: Cong Wang <cwang@multikernel.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracting the vmlinux from a bzImage was the one place where
kerfran an external program at runtime:lz4 -d -cfor an LZ4 kernel, always.zstd -d -cfor a zstd kernel when thezstandardmodule was missing, which is any plain install, since the module was never a dependency.This removes
_decompress_cliand uses thezstandardandlz4Python modules instead. After this,kerfruns no external command at runtime.Changes
zstandardonly, with no fallback to thezstdbinary.lz4 -l, the legacy format, which the frame API of thelz4module does not read.vmlinuz.pywalks the legacy blocks (at most 8 MB each, behind a compressed size) and decompresses each withlz4.block. The standard frame format goes throughlz4.frame.zstandardandlz4are added topyproject.toml, to the deb and rpm dependencies inpackaging/nfpm.yaml, and to the README.The modules are imported only when a kernel needs them. Without one,
kerf loadorkerf signof such a kernel fails with a message that names the missing module, and every other command keeps working.Testing
lz4 -l,lz4andzstdtools from a 27 MB input decompress to identical bytes, with and without an appended size.To check
The package names
python3-zstandardandpython3-lz4innfpm.yamlare unversioned and were not verified against specific distro releases.🤖 Generated with Claude Code