mkinitramfs supports compression that neither encodes size, nor is
guaranteed to signal the end of compressed archive. Linux refuses to
parse additional archives beyond the first compressed one - unless they
start at 4-byte boundary like uncompressed ones do.
I request
A) to modify mkninitramfs to append such padding and
B) to add tests to ensure concatenation keeps working (even after, say,
compression algo/lvl changes)
Rationale:
1. Documentation: After the requested change, inserting custom
configuration or installation prerequisites to provided installation
media will just work again. Append your changes, done.
2. It worked before: Without compression, still just works(tm). Should
never have been broken.
3. Debugging: With compression and before the requested change, raw cpio
and xz-compressed (len modulo 4 == 0) can be concatenated just fine. But
compressed-after-lz4 or raw-after-compressed makes the kernel ignore the
second half - and if that was not surprising enough, it *sometimes*
works, by chance.
4. Least surprise: With or without this change, alignment and/or EOF
signal might be added by the bootloader [10]. Since this can surprise
the person working on the image, it would be beneficial to preempt it in
ways visible in the filesystem.
Considerations:
5. Breaks reproducible builds: Post-change files are up to 0-3 bytes
bigger. See also #855357
6. Boot bugs: Unlikely, padding was always allowed; since the
introduction of lz4 even necessary.
7. Breakage in non-kernel Debian software: Unlikely; unmkinitramfs had
already been documented to not support multiple compressed archives.
Scripts would not depend on its behavior when parsing such anyway.
8. Breakage in bootloaders/firmware: Unlikely; all compression
algorithms (save xz) already sometimes produce the post-change
alignment, by (~25%) chance.
The attached sample code copies the desired bytes from /dev/zero. Also
attached is an autopkgtest script that calls qemu-system on the
concatenation of all currently supported compression algorithms in an
attempt to confirm that the kernel has not errorred out before parsing
the last one. It worked on my system, but even if it also works on
yours: beware that it is an amd64-only, non-EFI-only test.
dmesg samples, just to aid in detecting duplicates of this report
Initramfs unpacking failed: invalid magic at start of compressed archive
Initramfs unpacking failed: Decoding failed
Initramfs unpacking failed: broken padding
[10] see grub.git/grub-core/loader/linux.c@a8c473
[11] see linux.git/Documentation/filesystems/ramfs-rootfs-initramfs.rst