dracut

最後更新: 2021-03-01

介紹

dracut - low-level tool for generating an initramfs/initrd image

目錄

 


"dracut" Usage

 

dracut [OPTION...] [image [kernel-version]]

 * kernel-version 係對應 /lib/modules 內的 folder

 * If kernel version is omitted, then the version of the actual running kernel is used.

 * If <image> isomitted or empty, then the default location /boot/initramfs-<kernel version>.img is used.

Config File

  • /etc/dracut.conf
  • /etc/dracut.conf.d/*.conf

 


Contents in initramfs

 

# To see the contents of the image created by dracut

lsinitrd | grep vmxnet3

drwxr-xr-x   2 root     root            0 May 27 11:15 lib/modules/VERSION/kernel/drivers/net/vmxnet3
-rwxr--r--   1 root     root        90608 May 27 11:15 lib/modules/VERSION/kernel/drivers/net/vmxnet3/vmxnet3.ko

#  To display the contents of a file in the initramfs

lsinitrd -f /etc/ld.so.conf

 


Modules

 

# To see a list of available dracut modules

dracut --list-modules

# Omitting dracut Modules

dracut -o "multipath lvm" no-multipath-lvm.img

# 不 load 一堆用不到的 module

/etc/dracut.conf.d/myflags.conf

omit_dracutmodules+="iscsi resume lvm nbd rdma nfs cifs crypt crypt-loop crypt-gpg ecryptfs"

# Adding Kernel Modules to initramfs

# CLI

dracut --add-drivers "mymod" initramfs-with-mymod.img

# 亦可以在 /etc/dracut.conf.d/mymod.conf 設定

i.e.

echo 'add_drivers+=" ena"' > /etc/dracut.conf.d/ena.conf

 * 所有設定 add_drivers 必須有空格在前

 * The kernel modules have to be specified without the ".ko" suffix.

設定檔: /etc/dracut.conf.d/mymod.conf

dracutmodules+=" <dracut modules> "

Specify a space-separated list of dracut modules to call when building the initramfs.

Modules are located in /usr/lib/dracut/modules.d.

This option forces dracut to only include the specified dracut modules.

In most cases the "add_dracutmodules" option is what you want to use.

# Equivalent to -a "module"

add_dracutmodules+=" module" # Note leading space

# Equivalent to -o "module"

omit_dracutmodules+=" module" # Note leading space

Modules List

  • network      # Brings up network for net booting
  • ifcfg            # Generates network config at runtime
  • plymouth     # Includes boot animation
  • crypt
  • crypt-gpg
  • crypt-loop
  • ecryptfs

 


Kernel cmdline

 

# To get a quick start for the suitable kernel command line on your system

dracut --print-cmdline

man dracut.cmdline

Boot disable all USB storage devices

/etc/dracut.conf

kernel_cmdline="... rd.driver.blacklist=usb-storage,uas"

# dracut will automatically source this file and create a /etc/cmdline.d/01-default.conf file and place it inside the initramfs

/etc/dracut.conf.d/cmdline.conf -> initramfs(/etc/cmdline.d/01-default.conf)

加速 boot 機

rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0