systemd / mkosi

💽 Build Bespoke OS Images
https://mkosi.systemd.io/
GNU Lesser General Public License v2.1
1.14k stars 304 forks source link

initrd too large #2530

Closed Trumeet closed 5 months ago

Trumeet commented 5 months ago

I'm trying to build a Debian image for an embedded system, and the generated initrd seems to be about 150MiB. It takes too long for the embedded system to copy the whole initrd (inside UKI) from SD card to memory at boot.

Are there any ways to shrink the initrd, or use mkinitcpio?

The only thing (in my scenario) initrd has to do is to mount root in the same disk, and I am seeking ways to shrink the initrd as much as possible. Thanks.

Configuration file:

[Distribution]
Distribution=debian
Release=bookworm
Architecture=arm64

[Output]
Format=disk
CompressOutput=false
Output=image
OutputDirectory=out/
CacheDirectory=cache/
BuildDirectory=build/
ImageVersion=1.0
RepartDirectories=repart.d/

[Content]
Bootable=yes
Packages=linux-image-generic
         systemd
         systemd-boot
         systemd-sysv
         udev
         dbus
         openssh-server
         vim
         ncdu
Ssh=yes
RootPassword=redacted
Bootloader=systemd-boot
Locale=en_US.UTF-8
Timezone=America/Vancouver
Hostname=redacted
KernelCommandLine=systemd.volatile=yes loglevel=7 console=ttyS0 root=PARTLABEL=xxxxx

[Validation]
Checksum=yes
SignExpectedPcr=true

[Host]
Incremental=yes
QemuSmp=4
QemuMem=1G

With --debug-workspace, the image-initrd.cpio.zst is 36MiB, which extracts to a 134MiB CPIO. The merged UKI EFI is about 137MiB, and ukify inspect shows that the initrd is 105MiB.

Trumeet commented 5 months ago

It seems like mkosi is trying to do another brand-new Debian installation for initrd. Are there any ways to use mkinitcpio or another distribution (like Alpine to say?) that offers a smaller image?

DaanDeMeyer commented 5 months ago

Grep for settings with KernelModules in them in the docs.