Changing dracut initramfs Compression on Rocky Linux
Introduction
dracut builds the initramfs and compresses it with gzip by default. It can use other compressors instead (lz4, zstd, xz, and others), set through a dracut.conf.d drop-in. In almost all cases we recommend keeping the default gzip, which is the most broadly compatible option, and changing the compressor only if you have a specific, tested reason. This article shows how to change it, and what to confirm first, on Rocky Linux 8, 9, and 10.
Problem
You want to change the initramfs compressor from the default gzip, for example to shorten a workflow that regenerates the initramfs repeatedly.
Resolution
⚠️ WARNING We recommend leaving the compressor at the default gzip unless you have a specific, tested reason to change it. gzip is the most broadly compatible choice: every supported Rocky Linux kernel, including rescue and recovery kernels, can decompress it, and it needs no additional package. Other compressors only work when the matching tool is installed and the kernel can decompress that format at boot. Get either wrong and the affected node may fail to boot.
Set the compressor in a drop-in under /etc/dracut.conf.d/ rather than editing the package-owned /etc/dracut.conf. Files in /etc/dracut.conf.d/ are read in alphanumeric order and override /etc/dracut.conf.
Create a drop-in with the compress= directive:
# /etc/dracut.conf.d/90-compress.conf
compress="lz4"
Per dracut.conf(5), compress= accepts gzip (the default), bzip2, lzma, xz, lzo (this is lzop), lz4, and zstd.
Before regenerating, make sure both of these are true:
-
The compressor's tool is installed on the system building the initramfs.
lz4,zstd, andlzopcome from packages of the same name; if the tool is missing, the build fails. -
The kernel can decompress the format at boot. Each format has a matching config symbol; confirm it is enabled, and check the rescue kernel too:
grep -E 'CONFIG_RD_(GZIP|BZIP2|LZMA|XZ|LZO|LZ4|ZSTD)=' /boot/config-"$(uname -r)"Find the row for your chosen format; a value of
=ymeans the kernel supports it.
Then regenerate the initramfs for the installed kernels so the change takes effect:
sudo dracut --force --regenerate-all
Notes
- If you set the compressor through configuration management, apply it to one node and confirm it boots before rolling it out fleet-wide.
- Command-line compression flags (
--gzip,--lz4,--zstd, and so on) override the drop-in, which is useful for a one-off build without changing the configuration.
References & related articles
The compress= directive and the compression command-line options are documented in the dracut.conf and dracut man pages (also available on any Rocky Linux system with man dracut.conf and man dracut).