3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
8 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
13 # 80x25 linebreak here ^
14 echo "Usage: $0 [OPTION]... <initramfs> <kernel-version>
15 Creates initial ramdisk images for preloading modules
17 -f, --force Overwrite existing initramfs file.
18 -m, --modules [LIST] Specify a space-separated list of dracut modules to
19 call when building the initramfs. Modules are located
20 in /usr/share/dracut/modules.d.
21 -o, --omit [LIST] Omit a space-separated list of dracut modules.
22 -a, --add [LIST] Add a space-separated list of dracut modules.
23 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
24 include in the initramfs.
25 -k, --kmoddir [DIR] Specify the directory, where to look for kernel modules
26 --fwdir [DIR] Specify additional directory, where to look for
28 -h, --help This message
29 --debug Output debug information of the build process
30 -v, --verbose Verbose output during the build process
31 -c, --conf [FILE] Specify configuration file to use.
32 Default: /etc/dracut.conf
33 -l, --local Local mode. Use modules from the current working
34 directory instead of the system-wide installed in
35 /usr/share/dracut/modules.d.
36 Useful when running dracut from a git checkout.
37 -H, --hostonly Host-Only mode: Install only what is needed for
38 booting the local host instead of a generic host.
39 -i, --include [SOURCE] [TARGET]
40 Include the files in the SOURCE directory into the
41 Target directory in the final initramfs.
42 -I, --install [LIST] Install the space separated list of files into the
49 -f|
--force) force
=yes;;
50 -m|
--modules) dracutmodules_l
="$2"; shift;;
51 -o|
--omit) omit_dracutmodules_l
="$2"; shift;;
52 -a|
--add) add_dracutmodules_l
="$2"; shift;;
53 -d|
--drivers) drivers_l
="$2"; shift;;
54 -k|
--kmoddir) drivers_dir_l
="$2"; shift;;
55 --fwdir) fw_dir_l
="$2"; shift;;
56 -h|
--help) usage
; exit 1 ;;
57 --debug) debug
="yes";;
58 -v|
--verbose) beverbose
="yes";;
59 -c|
--conf) conffile
="$2"; shift;;
60 -l|
--local) allowlocal
="yes" ;;
61 -H|
--hostonly) hostonly
="-h" ;;
62 -i|
--include) include_src
="$2"; include_target
="$3"; shift 2;;
63 -I|
--install) install_items
="$2"; shift;;
69 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/usr
/sbin
:/usr
/bin
:/sbin
:/bin
:$PATH
72 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
76 # if we were not passed a config file, try the default one
77 [[ ! -f $conffile ]] && conffile
="/etc/dracut.conf"
79 # source our config file
80 [[ -f $conffile ]] && .
"$conffile"
82 # these options override the stuff in the config file
83 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodules_l
84 [[ $omit_dracutmodules_l ]] && omit_dracutmodules
=$omit_dracutmodules_l
85 [[ $add_dracutmodules_l ]] && add_dracutmodules
="$add_dracutmodules $add_dracutmodules_l"
86 [[ $drivers_l ]] && drivers
=$drivers_l
87 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
88 [[ $fw_dir_l ]] && fw_dir
=$fw_dir_l
89 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/share
/dracut
91 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc
="$(dirname $0)" || dsrc
=$dracutbasedir
93 if [[ -f $dsrc/dracut-functions
]]; then
94 .
$dsrc/dracut-functions
96 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
97 echo "Try passing -l as an argument to $0"
101 dracutfunctions
=$dsrc/dracut-functions
102 export dracutfunctions
104 # This is kinda legacy -- eventually it should go away.
105 case $dracutmodules in
106 ""|auto
) dracutmodules
="all" ;;
109 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
110 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
112 if [[ -f $outfile && ! $force ]]; then
113 echo "Will not override existing initramfs ($outfile) without --force"
117 hookdirs
="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
119 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
120 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
122 # Need to be able to have non-root users read stuff (rpcbind etc)
125 export initdir hookdirs dsrc dracutmodules drivers \
126 fw_dir drivers_dir debug beverbose
128 # Create some directory structure first
129 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot tmp dev
/pts var
/run
; do
130 mkdir
-p "$initdir/$d";
133 # check all our modules to see if they should be sourced.
134 # This builds a list of modules that we will install next.
138 for moddir
in "$dsrc/modules.d"/[0-9][0-9]*; do
139 mod
=${moddir##*/}; mod
=${mod#[0-9][0-9]}
140 if strstr
"$mods_to_load" " $mod "; then
142 mods_to_load
=${mods_to_load// $mod /}
148 ## final stuff that has to happen
150 # generate module dependencies for the initrd
151 if [ -d "$initdir/lib/modules/$kernel" ]; then
152 if ! depmod
-a -b "$initdir" $kernel; then
153 echo "\"depmod -a $kernel\" failed."
158 # make sure that library links are correct and up to date
159 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
161 if [[ $include_src && $include_target ]]; then
162 mkdir
-p "$initdir$include_target"
163 cp -a -t "$initdir$include_target" "$include_src"/*
166 for item
in $install_items; do
167 dracut_install
"$item"
171 [[ "$beverbose" = "yes" ]] && (du
-c "$initdir" |
sort -n)
173 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )
175 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"