Can the initramfs image use a compression format other than gzip?

11,926

Solution 1

Yes. I use in-kernel initrd and it offers at least the following methods:

  • None (as it is compressed with kernel)
  • GZip
  • BZip
  • LZMA (possibly zen-only)

You can use it on external file and with LZMA (at least on Ubuntu).

Wikipedia states that Linux kernel supports gzip, bzip and lzma (depending, of course, what algorithms are compiled in).

Solution 2

v4.15 INITRAMFS_COMPRESSION_*

These kernel config options determine if compression is enabled or not.

A quick:

git grep INITRAMFS_COMPRESSION_

on the kernel tree leads to:

usr/Kconfig:134:config INITRAMFS_COMPRESSION_NONE
usr/Kconfig:145:config INITRAMFS_COMPRESSION_GZIP
usr/Kconfig:155:config INITRAMFS_COMPRESSION_BZIP2
usr/Kconfig:168:config INITRAMFS_COMPRESSION_LZMA
usr/Kconfig:181:config INITRAMFS_COMPRESSION_XZ
usr/Kconfig:194:config INITRAMFS_COMPRESSION_LZO
usr/Kconfig:206:config INITRAMFS_COMPRESSION_LZ4

Solution 3

You can see what compressions are supported for initramfs with:

zgrep CONFIG_RD_ /proc/config.gz
# or
grep CONFIG_RD_ /usr/src/linux/.config
Share:
11,926

Related videos on Youtube

uray
Author by

uray

i'am a programmer

Updated on September 17, 2022

Comments

  • uray
    uray over 1 year

    Can the initramfs image be compressed by a method other than gzip, such as lzma?

  • uray
    uray over 13 years
    does it must be "in-kernel" initrd (and what do you actually means by in-kernel) ? what if I have external file of initrd?
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    I would be very surprised if it used different files. As in what it actually means - you can build-in initrd in kernel just as you can build-in modules. I have / on LVM so I need to have initrd script - and the easiest way for me is to build it into kernel.
  • uray
    uray over 13 years
    sorry but the 'initrd' in this question is actually an initramfs file or a filesystem that initially loaded by kernel, or the file which usually pointed by grub like this initrd /boot/initramfs-2.6.33.3-85.fc13.i686.img, maybe I used wrong term (I edited the question)?
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    As I stated in edit - yes at least in Ubuntu. I'd be very surprised if it hadn't work. You haven't used the wrong term but I said what 1) I have experience with 2) what I found (that Ubuntu do support it) 3) what I expect. Anyway - why not just try it.
  • uray
    uray over 13 years
    ok I tried it, it confirmed the kernel can load initramfs with lzma compression, I must compile the kernel using CONFIG_RD_LZMA=y. but it will KP if the compression parameter is other than default, for example if i try lzma -e -9 -z for initramfs image it will leads to KP.
  • Ciro Santilli Путлер Капут 六四事
    Ciro Santilli Путлер Капут 六四事 about 6 years
    The initramfs options are apparently called: INITRAMFS_COMPRESSION_, I think CONFIG_RD_ are for initrd? unix.stackexchange.com/a/429880/32558
  • Stephan Henningsen
    Stephan Henningsen over 3 years
    Ohh! Thanks for zgrep! =)
  • Admin
    Admin almost 2 years
    I believe this is only relevant for a "built in initramfs" (see github.com/torvalds/linux/blob/…). For most uses of initramfs (e.g. at boot time on Debian/Ubuntu) an external file is used. For that way of working, the CONFIG_RD_ options apply