Occasionally, the initramfs image may get damaged as well. If this happens, you cannot boot your server into normal operational mode. To repair the initramfs image after booting into the rescue environment, you can use the dracut command. If used with no arguments, this command creates a new initramfs for the kernel currently loaded.
Alternatively, you can use the dracut command with several options to make an initramfs for specific kernel environments. There is also a configuration file with the name /etc/dracut.conf that you can use to include specific options while re-creating the initramfs.
An example of using the dracut command to create an initramfs image is as follows:
# dracut /boot/initramfs-$(uname -r).img $(uname -r)
If you encounter the below error while running the dracut command:
dracut: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install dracut |
Ubuntu | apt-get install dracut |
Kali Linux | apt-get install dracut |
CentOS | yum install dracut |
Fedora | dnf install dracut |
Raspbian | apt-get install dracut |
Conclusion
The dracut command is used to generate an initramfs image, similar to how mkinitrd is used to generate an initrd image. In fact, on some distributions, mkinitrd is a compatibility wrapper that calls the dracut command.