Damn Small Linux Forums
RC6: With optimization of initrd, it boots the installation with 64 MB! - Printable Version

+- Damn Small Linux Forums (https://damnsmalllinux.org/forums)
+-- Forum: Damn Small Linux Forum (https://damnsmalllinux.org/forums/forum-1.html)
+--- Forum: User Feedback (https://damnsmalllinux.org/forums/forum-2.html)
+--- Thread: RC6: With optimization of initrd, it boots the installation with 64 MB! (/thread-168.html)



RC6: With optimization of initrd, it boots the installation with 64 MB! - mifritscher - 10-02-2024

The Initrd of an installed version as grown to compressed 40 MB. This means that it needs at least 256 MB RAM (on 128 MB, it decompresses but chrashes later)

So: Is there a method to archive a smaller initrd?

The main contents:
* 7 MB intel microcode (I think these get purged early, so no problem)
* 32 MB "main" initrd", which gets decompressed to 76 MB

the main initrd:
Most in lib
* 12 MB firmware
* 14 MB lib
* 49 MB modules

Most of the firmware is for network stuff. Perhaps it is useful to ask whether it should be used for PXE boot - because if not this is not needed ;-)

Lib: Crypto is about 5 MB. Only needed for crypted devices. (and why libntfs?)

modules:
1.1 M crypto - only needed for cryptsetup and perhaps enforcing secure boot
39 MB drivers
16 MB net - only needed for PXE-boot
1,5 MB infiniband - I think nobody starts this from infiniband^^
8 MB scsi, ok, needed. Exceptions:
1 MB lpfc - "Emulex LightPulse Fibre Channel" - is not exactly used that often for boot
0,9 MB qla2xxx - "QLogic Fibre Channel HBA Driver" - is not exactly used that often for boot
0,5 MB bfa - "QLogic BR-series Fibre Channel" - is not exactly used that often for boot

5.3 MB fs - 1.2 MB nfs, only needed for pxeboot
1.5 MB net - only needed for pxeboot

so about 38 MB could be saved.

I want ahead. this made about 37 MB initrd, which gets compressed to 14 MB.

Ok now I got more aggressive and killed more (iscsi, ntfs-3g, fuse, btrfs/f2fs/jfx/xfs, sound) - 31/11 MB.

This did not work, because busybox has an hard dependency to libcrypto. But after adding that back (36/13,7 MB) I got it to work with 128 MB RAM! The whole system needs, regarding the desktop, 52 MB RAM + 7 MB swap.

This works even with only 96 MB. Even with 80 (getting an error not having an suitable RAM region for KASL, but started to desktop). The absolute minimum is 79 MB - Linux reports 63 MB then, the rest (16 MB) got eaten by the kernel.
But my target machine has even less RAM - 64 MB. 15 MB still missing.


Additionally, I think the kernel can use squashfs as initrd, so there is no decompression needed.

Problem: The kernel can not use squashfs as initramfs...

Next try: xz. Important: use --check=crc32, else the kernel can not work with it.

-6 made a 9.9 MB image, but needs too much memory for decompress.
-2 made a 11,4 MB image, but still 79 MB RAM is needed.

No compression of the initrd let grub bark out at a OOM - so no help here as well.

Ok, now I got way more aggressive and delete lots of stuff (forgotten btrfs binary, lots of modules)

-> 29,6 / 11,6 MB

The new RAM limit: 70 MB. Ok, 6 MB to go.

Ok, more killing. I tried to leave most of usb, scsi, ide, pcmcia intact.
Also removed the bin versions of the modules-files.
Additionally, somehow the hard link to busybox between bin and sbin got broken, fixed it with a

while [ true ]; do rdfind -makehardlinks true . ; done

(Type Ctrl+C when no dupplicates are found anymore)

-> 26,8/10,6 MB
The new RAM limit: 66 MB. Only 2 to go!

Tried upx on libcrypto.so.3, libext2fs.so.2.4 and libzstd.so.1.5.4 -> but not good as it kills the exports.

Used it on every binary but the busybox (I'm afraid that this hurts the perfomance too much), killed a forgotten ntfs-3g....

-> 25,6 / 10,5 MB

And it BOOTED with 64 MB!

Edit: You can download the last version of the initrd on
https://mifritscher.de/austausch/dsl/2024-rc6/initrd7 and
https://mifritscher.de/austausch/dsl/2024-rc6/initrd7.gz .

And a Screenshot:
https://mifritscher.de/austausch/dsl/2024-rc6/screenshot.png


RE: RC6: With optimization of initrd, it boots the installation with 64 MB! - grindstone - 10-03-2024

Good work, thanks for posting.

Pretty aggressive, but it's nice to have hard numbers. Appreciated.