Understanding how to use dracut is critical for kernel upgrades, troubleshooting boot issues, disk migration, encryption, and even kernel debugging.
🚀 Introduction: What is dracut?
dracut is a powerful tool used in Fedora, RHEL, and other distributions to create and manage initramfs images—the initial RAM filesystem used during system boot. Unlike older tools like mkinitrd, dracut uses a modular approach, allowing you to build minimal or specialized initramfs tailored to your system.
📦 Installing dracut (if not already available)
dracut comes pre-installed in Fedora and RHEL. If it is missing, install it with:
$ sudo dnf install dracut
Verify the version:
$ dracut --version
📂 Basic usage
📌 Regenerate the current initramfs
$ sudo dracut --force
This regenerates the initramfs for the currently running kernel.
📌 Generate initramfs for a specific kernel
$ sudo dracut --force /boot/initramfs-$(uname -r).img $(uname -r)
Or Manually!
$ sudo dracut --force $ sudo dracut --force /boot/initramfs-5.14.0-327.el9.x86_64.img 5.14.0-327.el9.x86_64
🧠 Understanding key dracut options (with examples)
–force
Force regeneration even if the file already exists:
$ sudo dracut --force
–kver <kernel-version>
Generate initramfs for a specific kernel:
$ sudo dracut --force --kver 5.14.0-327.el9.x86_64
–add <module> / –omit <module>
Include or exclude specific modules (e.g., lvm, crypt, network).
Include LVM module only:
$ sudo dracut --force --add lvm
Omit network module:
$ sudo dracut --force --omit network
–no-hostonly
Build a generic initramfs that boots on any compatible machine:
$ sudo dracut --force --no-hostonly
–hostonly
Create a host-specific image for minimal size:
$ sudo dracut --force --hostonly
–print-cmdline
Show the kernel command line:
$ dracut --print-cmdline
–list-modules
List all available dracut modules:
$ dracut --list-modules
–add-drivers “driver1 driver2”
Include specific drivers:
$ sudo dracut --add-drivers "nvme ahci" --force
🧪 Test cases and real-world scenarios
1. LVM root disk fails to boot after migration
$ sudo dracut --force --add lvm --hostonly
2. Initramfs too large
Shrink it by omitting unused modules:
$ sudo dracut --force --omit network --omit plymouth
3. Generic initramfs for provisioning
$ sudo dracut --force --no-hostonly --add network --add nfs
4. Rebuild initramfs for rollback kernel
$ sudo dracut --force /boot/initramfs-5.14.0-362.el9.x86_64.img 5.14.0-362.el9.x86_64
🪛 Advanced use: Debugging and analysis
Enable verbose output:
$ sudo dracut -v --force
Enter the dracut shell if boot fails:
Use rd.break in the GRUB kernel line.
📖 Where is dracut configuration stored?
There are two locations where configuration setting may occur.
The global settings location is at:
/etc/dracut.conf
and the drop-in location is at:
/etc/dracut.conf.d/*.conf
Example using the drop-in location:
$ cat /etc/dracut.conf.d/custom.conf
The contents might appear as follows for omitting and adding modules:
omit_dracutmodules+=" plymouth network "
add_dracutmodules+=" crypt lvm "
⚠️ Note: Always include a space at the beginning and end of the value when using += in these configuration files. These files are sourced as Bash scripts, so
ensures proper spacing when multiple config files are concatenated. Without the spaces, the resulting string could concatenate improperly (e.g., mod2mod3) and cause module loading failures.add_dracutmodules+=" crypt lvm "
🧠 Deep dive: /usr/lib/dracut/modules.d/ – the heart of dracut
The directory /usr/lib/dracut/modules.d includes all module definitions. Each contains:
- A module-setup.sh script
- Supporting scripts and binaries
- Udev rules, hooks, and configs
List the modules using the following command:
$ ls /usr/lib/dracut/modules.d/
Example output:
01fips/ 30crypt/ 45ifcfg/ 90lvm/ 95resume/ 02systemd/ 40network/ 50drm/ 91crypt-gpg/ 98selinux/
Inspect specific module content (module-setup.sh, in this example) using this:
$ cat /usr/lib/dracut/modules.d/90lvm/module-setup.sh
You can also create custom modules at this location for specialized logic.
🏁 Final thoughts
dracut is more than a utility—it’s your boot-time engineer. From creating lightweight images to resolving boot failures, it offers unparalleled flexibility.
Explore man dracut, read through /usr/lib/dracut/modules.d/, and start customizing.
💡 This article is dedicated to my wife, Rupali Suraj Patil, for her continuous support and encouragement.
Oscar
Hey, mkosi-initrd is meant to replace dracut, isn’t?
https://fedoraproject.org/wiki/Changes/mkosi-initrd
Adam Williamson
Not yet.
“The goal of this change is to provide an alternative mechanism.”
mogoh
I am sorry and I might be wrong, but when I see headlines starting with “random” emojis, I think it was written by ChatGPT and its kind.
SeeM
It’s just a good sumarry, which a model could provide anyway.
alk
Sadly this content is clearly generated with AI.
Gregory Bartholomew
I asked and the author said AI was not used. It is best to not cast aspersions.
Jack
I agree with the harm caused by assuming everything is AI. A clear and concise article like this which is written by a human means a lot, and pointing fingers in the FOSS journalism community is the last thing authors need.
What is true though is that this article will soon be in a bunch of datasets…
SeeM
–no-hostonly is super handy before migrating VM to a different host, usually with a different cpu. You’ll figure that out, eventually.
klaas
if you want to make it permanent just use “dnf install dracut-config-generic”
Tom
Suraj you’ve been putting out great articles. Really enjoying reading them.
Jack
I’ve always wondered how to add Bluetooth to Dracut, since it gives a warning when run manually. I never figured it out in the manual, but this article explains it clearly.
Would adding bluetooth via dracut add bluetooth to Grub?