How To Shrink initramfs
The approach described here in this tutorial works prefectly for the kernel and rootfs I releases: Kirkwood and MVEBU.
In general, it should work for any Debian kernel. However, it aso depends on how a particular kernel is configured. IOW, whether the necessary mouldes were already built into the kernel, or some other loadable modules must be loaded early. Please post your question in this thread.
1. Change the default modules loading to dep.
Edit the file /etc/initramfs-tools/initramfs.conf
2. Update initramfs
I'm using the kernel 6.3.5-kirkwood-tld-1 as an example here. Adjust this to the appropriate version number to the running kernel in your system (run uname -a to display current kernel version).
It will take sometime for the update to complete. List the initramfs files to see the size change. It should shrink the iniramfs by 50% or more.
3. Recreate the boot file uInitrd
So now we have a new initrd.img-6.3.5-kirkwood-tld-1 file, we need to recreate uInitrd.
4. Reboot
If satisfied with the new size for initramfs, reboot the system.
5. (Optional) Use lzma or zstd compression
Sometime you need to shrink the initramfs even more. For example, in order to flash it to a limited size NAND flash partition (like for boxes in the WD MyCloud NAS series). Then change the compression to lzma or zstd (available in bullseye and bookworm). Note that to use zstd compression, you also need to install zstd in Debian (apt-get install zstd) first.
Warning: for low RAM boxes (128MB and perhaps also 256MB) like with a few Kirkwood plugs, I'd recommend that you use gzip only. Don't use lzma or zstd because it is too slow.
Edit the file /etc/initramfs-tools/initramfs.conf
And then update the initramfs as described in Step 2.
It will take sometime for the update to complete. List the initramfs files to see the size change. It should shrink the iniramfs substantially (about 20% or more).
And then recreate the boot file uInitrd as shown in Step 3 above. But this time specify the compression.
And then reboot the system.
The approach described here in this tutorial works prefectly for the kernel and rootfs I releases: Kirkwood and MVEBU.
In general, it should work for any Debian kernel. However, it aso depends on how a particular kernel is configured. IOW, whether the necessary mouldes were already built into the kernel, or some other loadable modules must be loaded early. Please post your question in this thread.
1. Change the default modules loading to dep.
Edit the file /etc/initramfs-tools/initramfs.conf
# MODULES: [ most | netboot | dep | list ]
# dep - Try and guess which modules to load.
MODULES=dep
2. Update initramfs
I'm using the kernel 6.3.5-kirkwood-tld-1 as an example here. Adjust this to the appropriate version number to the running kernel in your system (run uname -a to display current kernel version).
cd /boot ls -lh initrd.img-6.3.5-kirkwood-tld-1 update-initramfs -u
It will take sometime for the update to complete. List the initramfs files to see the size change. It should shrink the iniramfs by 50% or more.
ls -lh initrd.img-6.3.5-kirkwood-tld-1
3. Recreate the boot file uInitrd
So now we have a new initrd.img-6.3.5-kirkwood-tld-1 file, we need to recreate uInitrd.
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs-6.3.5-kirkwood-tld-1 -d initrd.img-6.3.5-kirkwood-tld-1 uInitrd sync
4. Reboot
If satisfied with the new size for initramfs, reboot the system.
sync shutdown -r now
5. (Optional) Use lzma or zstd compression
Sometime you need to shrink the initramfs even more. For example, in order to flash it to a limited size NAND flash partition (like for boxes in the WD MyCloud NAS series). Then change the compression to lzma or zstd (available in bullseye and bookworm). Note that to use zstd compression, you also need to install zstd in Debian (apt-get install zstd) first.
Warning: for low RAM boxes (128MB and perhaps also 256MB) like with a few Kirkwood plugs, I'd recommend that you use gzip only. Don't use lzma or zstd because it is too slow.
Edit the file /etc/initramfs-tools/initramfs.conf
# COMPRESS: [ gzip | bzip2 | lzma | lzop | xz ]
COMPRESS=lzma
And then update the initramfs as described in Step 2.
It will take sometime for the update to complete. List the initramfs files to see the size change. It should shrink the iniramfs substantially (about 20% or more).
ls -lh initrd.img-6.3.5-kirkwood-tld-1
And then recreate the boot file uInitrd as shown in Step 3 above. But this time specify the compression.
mkimage -A arm -O linux -T ramdisk -C lzma -a 0x00000000 -e 0x00000000 -n initramfs-6.3.5-kirkwood-tld-1 -d initrd.img-6.3.5-kirkwood-tld-1 uInitrd
And then reboot the system.
sync shutdown -r now