I am following the instructions here to build a custom kernel directly from kernel.org tarballs, to test some driver issues. The process works overall, but the initramfs file generated is always too big (~300MB compared to the ~90MB from Fedora official kernels):
❯ ls -lh /boot/initramfs-*
-rw-------. 1 root root 89M mar 2 2022 /boot/initramfs-0-rescue-0f3fba885cee468088d4182aec827349.img
-rw-------. 1 root root 86M ago 21 16:58 /boot/initramfs-6.15.10-200.fc42.x86_64.img
-rw-------. 1 root root 59M jul 30 08:24 /boot/initramfs-6.15.8-200.fc42.x86_64.img
-rw-------. 1 root root 86M ago 6 15:09 /boot/initramfs-6.15.9-201.fc42.x86_64.img
-rw-------. 1 root root 302M ago 23 17:46 /boot/initramfs-6.17.0-rc2-costa.img
Comparing the contents of /boot/initramfs-6.17.0-rc2-costa.img with /boot/initramfs-6.15.10-200.fc42.x86_64.img shows that on the initramfs-6.17.0-rc2 the kernel modules are not compressed (.ko instead of .ko.xz), and so are the modules at /lib/modules/6.17.0-rc2-costa. I copied .config file for 6.15.10, and it does include CONFIG_MODULE_COMPRESS=y and CONFIG_MODULE_COMPRESS_XZ=y, so, why are modules not compressed? I noticed CONFIG_MODULE_COMPRESS_ALL is not set, could this be the issue?
Hello,
for xz compress modules you could dracut parameter (for example): make modules XZ_OPT=-T0 = it works well - for modules. But I don’t know this paramater for initramfs. I tried: dracut -v --xz -f /boot/initramfs-XXX, but without success. I there anybody who know it? Thanks.
I did manage to compress kernel modules by setting CONFIG_MODULES_COMPRESS_ALL=y before compiling. However, the resulting initramfs shrank only by a couple of MB, still being much larger then the official Fedora files (283MB vs. 86MB). There is still some additional steps I am missing…
what version of kernel are you using? In version 6.16.7 isn’t parameter CONFIG_MODULES_COMPRESS_ALL=y. I think, that you could use CONFIG_MODULE_COMPRESS=y and CONFIG_MODULE_COMPRESS_XZ=y. I tried it with version 6.15.XX and parametr make -j14 modules XZ_OPT=-T0 worked automatically well. But it works two months ago, just now not… I don’t know why.
man xz:
..
XZ_OPT This is for passing options to xz when it is not possible to set the options directly on the xz command line. This is
the case when xz is run by a script or tool, for example, GNU tar(1):
XZ_OPT=-2v tar caf foo.tar.xz foo
Scripts may use XZ_OPT, for example, to set script-specific default compression options. It is still recommended to al‐
low users to override XZ_OPT if that is reasonable. For example, in sh(1) scripts one may use something like this:
XZ_OPT=${XZ_OPT-"-7e"}
export XZ_OPT
..
Test:
$ XZ_OPT=2v tar cf maemo_overclock.txt.xz maemo_overclock.txt
$ echo $?
0
$ l maemo_overclock.tar.xz
-rw-r–r-- 1 vzakovec vzakovec 10240 Sep 15 14:20 maemo_overclock.tar.xz
$ file maemo_overclock.tar.xz
maemo_overclock.tar.xz: POSIX tar archive (GNU)
$ unxz maemo_overclock.tar.xz
unxz: maemo_overclock.tar.xz: File format not recognized
It means that there is xz bug or in the system environment…(?) - again, it work two months ago…
Kernel modules (*.ko) without compression has about 9.7 GB, this isn’t acceptable.
I’m using kernel config from distribution kernel, but it is useless for my HW. It would be better to run make menuconfig and select modules and etc only for my HW, but it is a bit torture…, lsmod should help. But I expect, that kernel and initramfs should be smaller and faster.
The initramfs is compressed via dracut.
It is my /boot:
-rw-r–r-- 1 root root 10645144 Sep 14 17:21 System.map-6.16.7
-rw-r–r-- 1 root root 11839788 Sep 11 02:00 System.map-6.16.7-200.fc42.x86_64
-rw-r–r-- 1 root root 289946 Sep 11 02:00 config-6.16.7-200.fc42.x86_64
drwx------ 4 root root 16384 Jan 1 1970 efi
drwxr-xr-x. 2 root root 4096 May 28 11:42 extlinux
drwx------. 4 root root 4096 Sep 14 14:51 grub2
-rw------- 1 root root 149779659 Sep 12 16:03 initramfs-6.16.7-200.fc42.x86_64.img
-rw------- 1 root root 230255308 Sep 14 17:22 initramfs-6.16.7.img
drwxr-xr-x. 3 root root 4096 Oct 25 2018 loader
drwx------. 2 root root 4096 Jan 26 2019 lost+found
-rw-r–r-- 1 root root 157184 Jan 17 2025 memtest86+x64.efi
lrwxrwxrwx 1 root root 46 Sep 12 16:02 symvers-6.16.7-200.fc42.x86_64.xz → /lib/modules/6.16.7-200.fc42.x86_64/symvers.xz
-rw-r–r-- 1 root root 12751360 Sep 14 17:21 vmlinuz-6.16.7
-rwxr-xr-x 1 root root 17656168 Sep 11 02:00 vmlinuz-6.16.7-200.fc42.x86_64
My kernel config is the same (now) as for kernel-6.16.7-200.fc42.x86_64, but initramfs is still a bit bigger, why? I’m a bit busy now, but I expect, that I will run make menuconfig…
I will find solution of compression of modules and I will inform…
I must corect me there.
The fatal value of modules compress is really CONFIG_MODULES_COMPRESS_ALL=y, my apology. This parameter was hidden in my make menuconfig. I use “vanilla” kernel from kernel.org and .config of RH/Fedora is for their patched kernel. Hmm, Welcome in the hell of kernel configuration… But this is the best way to optimize kernel and HW.
The option XZ_OPT is only xz option, it is not necessary for compression of modules.
Aside from compression, what seems to impact the file size the most is including or not some modules, in my case notably amdgpu files. You can control which ones are included by setting up a .conf file in /etc/dracut.conf.d/ , for example I created a no-amdgpu.conf file there with:
omit_drivers+=" amdgpu "
(beware of the spaces surrounding the module name)