I am using dracut to create an initramfs to test a script for creating a key in the TPM chip. For now, this script is just a dummy script, so I can see if I've created the initramfs correctly:

#!/usr/bin/env bash
read -p 'This file will run to initialize the TPM'
exit 0

I want to include this script in the pre-mount boot phase. I followed the answer to the question "How to write a pre-mount startup script?" in this forum, modifying it as necessary, but when I list the contents of the image file, my scripts are not there. I also tried using the --include and --install dracut options, but I either receive an error, or if I don't, the scripts are not in the initramfs. I named my file tpm.img, and placed it in the /boot directory. When booting the computer, I press 'e' to modify the grub line, and change the initrdefi command to point to my tpm.img. Of course, my script doesn't run, because it's not present in the initramfs. I'm not sure that I understand the "Injecting custom Files" section of the dracut manual:


I haven't been able to find any examples of dracut configuration files or dracut command line files that show the complete path to the module to be included. Please help me understand why my script is not being included in the initramfs.

Thanks! Jeff

2 Answers 2


I had success with --include. Assuming you put you custom script in /etc/dracut.conf.d/tpm.sh, you can do:

sudo dracut --include /etc/dracut.conf.d/tpm.sh /usr/lib/dracut/hooks/pre-mount/tpm.sh tpm.img

The file is there:

$ sudo lsinitrd tpm.img | grep -F tpm.sh
Arguments: --include '/etc/dracut.conf.d/tpm.sh' '/usr/lib/dracut/hooks/pre-mount/tpm.sh'
-rw-rw-r--   1 root     root           80 Apr  5 17:22 usr/lib/dracut/hooks/pre-mount/tpm.sh

Unfortunately as far as I know, there is no configuration file equivalent for the --include command line option. There is install_items, which is the equivalent for --install. This option only takes one path as the path in the initramfs is the same as in the main FS. So you need to put your script at /usr/lib/dracut/hooks/pre-mount/tpm.sh. Then you can create /etc/dracut.conf.d/tpm.conf:

install_items+=" /usr/lib/dracut/hooks/pre-mount/tpm.sh "

This will cause all future automatically generated initramfs images to include the script, for example when upgrading your kernel.


Another option is creating a "module" in /usr/lib/dracut/modules.d. Inside that directory, you can create a dedicated 90tpm directory and put your tpm.sh inside. You also need to put in a special script called module-setup.sh, whose install function is called by dracut at build time. A simple module-setup.sh can look like this:

#! /bin/bash

install () { inst_hook pre-mount 50 "$moddir/tpm.sh"; }

Then you can call dracut without any extra arguments or configuration files:

[~]$ ls -l /usr/lib/dracut/modules.d/90tpm
total 8
-rwxr-xr-x. 1 root root 70 Jun  4 01:57 module-setup.sh
-rwxr-xr-x. 1 root root 80 Jun  4 01:46 tpm.sh
[~]$ sudo dracut test.img
[~]$ sudo lsinitrd test.img | grep tpm
-rwxr-xr-x   1 root     root           80 Apr  5 17:22 usr/lib/dracut/hooks/pre-mount/50-tpm.sh
  • Does anybody have any idea where the "Apr 5 17:22" timestamp comes from? That is quite different from the timestamp in the FS.
    – Karel Vlk
    Commented Jun 4, 2023 at 0:18
  • Note that module-setup.sh might not work with dracut versions before 008 (RHEL 6). See unix.stackexchange.com/questions/611882/… .
    – Karel Vlk
    Commented Jun 4, 2023 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .