Score:0

Issue with initrd compression

ru flag

initrd compression enabled on config file, but kernel images are not compressed.

hkk@hkk-NUC7CJYH:~$ grep COMPRESS /etc/initramfs-tools/initramfs.conf
COMPRESS=gzip

hkk@hkk-NUC7CJYH:/boot$ file initrd.img-5.8.0-43-generic
initrd.img-5.8.0-43-generic: ASCII cpio archive (SVR4 with no CRC)

Ubuntu VERSION="20.04.2 LTS (Focal Fossa)"

Just wondering if I need perform any additional config to compress the kernel image. Appreciate the help!

HuHa avatar
es flag
If the kernels have names like "vmlinuz...", they are compressed.
heynnema avatar
ru flag
The kernel doesn't get compressed with the info that you're looking at. Only the initrd.img file is gzip compressed.
hkk01 avatar
ru flag
@HuHa vmlinuz is compressed, how can I compress initrd images?
hkk01 avatar
ru flag
@heynnema no, even initrd.img is not compressed here
HuHa avatar
es flag
The `mkinitramfs` script should do that automatically. It also has an explicit `-c` ("compressed") parameter; the man page says this is for overriding the `initramfs.conf` file.
HuHa avatar
es flag
My kernels are listed like this with `sudo file /boot/vmlinu*`: `/boot/vmlinuz-4.15.0-147-generic: Linux kernel x86 boot executable bzImage, version 4.15.0-147-generic (buildd@lcy01-amd64-028) #151-Ubuntu SMP Fri Jun 18 19:21:19 UTC 2021, RO-rootFS, swap_dev 0x8, Normal VGA`; notice the `bzImage` part.
heynnema avatar
ru flag
Your initrd.img file IS compressed. Just do `more initrd.img-5.8.0-43-generic`. Why are you worrying about this? The files are just like they're supposed to be.
hkk01 avatar
ru flag
@heynnema just trying to learn different compression method and booting time difference, but initrd.img is not getting compressed even I pass -c parameter in mkinitramfs command.
heynnema avatar
ru flag
If you just did the command from my last comment, you'd see that the file is compressed. You shouldn't be using the `mkinitramfs` command, you should be using `update-initramfs` command.
hkk01 avatar
ru flag
@heynnema I tried both, but it doesn't compress. while using mkinitramfs command I have specified output file location as well, but doesn't work either.
hkk01 avatar
ru flag
/boot$ sudo update-initramfs -u -k all update-initramfs: Generating /boot/initrd.img-5.8.0-43-generic hkk@hkk-NUC7CJYH:/boot$ file initrd.img-5.8.0-43-generic initrd.img-5.8.0-43-generic: ASCII cpio archive (SVR4 with no CRC) hkk@hkk-NUC7CJYH:/boot$ sudo mkinitramfs -c gzip -o /boot/initrd.img-5.8.0-43-generic hkk@hkk-NUC7CJYH:/boot$ file initrd.img-5.8.0-43-generic initrd.img-5.8.0-43-generic: ASCII cpio archive (SVR4 with no CRC)
heynnema avatar
ru flag
Sigh. Did you do the `more` command? No you didn't. You're also still using the `mkinitramfs` command. You're chasing your tail on a problem that doesn't exist.
hkk01 avatar
ru flag
more result 07070100000065000041ED00000000000000000000000260D054A400000000000000030000000100000000000000000000000700000000kernel0100000066000041ED00000000000000000000000260D054A400000000000000030000000100000000000000000000000B00000000kernel/x860100000067000041ED00000000000000000000000260D054A400000000000000030000000100000000000000000000001500000000kernel/x86/mic /:1ῧZ:=wv'̶vFpiP蒜(͌.?R6C0OXa2j|x^Yf1Aq'At@ 棖9}o;T> ,k-%!y}., Okb ?^L&J`&x:ECn;EEs+vu SYI_ܧffv<ry!TЕaTƐ_˨|)~'9w ExXKܞ'n:BE:J~\H?Cu0i!N#> U$z_8^^LeȎ/<^(*qA=YZ)Sq-*NU2#CX~
heynnema avatar
ru flag
You forgot to tag me with @heynnema, so I missed your update. The `more` command shows that this is a gzip compressed file.
hkk01 avatar
ru flag
Thanks @heynnema. I figured it out, when intel microcode is installed initrd is uncompressed CPIO archive, and if you remove microcode it will be gzip compressed file.
heynnema avatar
ru flag
@hkk01 I don't think that's correct. And, as I said, I think that you're chasing a problem that doesn't exist.
Score:0
uz flag

First of all as mentioned. You're wanting the initrd not the kernel image compressed. And you have everything configured correctly for it to be compressed.

You are also correct that it is not 100% compressed, and even appears to not be compressed at all because the first part of the initrd is a complete CPIO archive, which is uncompressed. As you discovered this uncompressed CPIO is the intel microcode update data. However the data following that first CPIO archive will be another compressed CPIO which is the main initrd archive.

The linux kernel can read multiple initrd archives concatenated together, even when some are compressed and some are not. According to a recent linux kernel, the initrd format is a follows:

*       is used to indicate "0 or more occurrences of"
(|)     indicates alternatives
+       indicates concatenation
GZIP()  indicates the gzip(1) of the operand
ALGN(n) means padding with null bytes to an n-byte boundary

initramfs  := ("\0" | cpio_archive | cpio_gzip_archive)*

cpio_gzip_archive := GZIP(cpio_archive)

cpio_archive := cpio_file* + (<nothing> | cpio_trailer)

cpio_file := ALGN(4) + cpio_header + filename + "\0" + ALGN(4) + data

cpio_trailer := ALGN(4) + cpio_header + "TRAILER!!!\0" + ALGN(4)

Although, I don't think this is up-to-date either as more than gzip compression is supported. Also, I believe there is a bug in the kernel where an uncompressed CPIO archive can not follow a compressed one. Another thing to keep is mind is that if there are duplicate paths in the various initrds, the data of last one will be used.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.