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 -h, --help This message
27 --debug Output debug information of the build process
28 -v, --verbose Verbose output during the build process
29 -c, --conf [FILE] Specify configuration file to use.
30 Default: /etc/dracut.conf
31 -l, --local Local mode. Use modules from the current working
32 directory instead of the system-wide installed in
33 /usr/share/dracut/modules.d.
34 Useful when running dracut from a git checkout.
35 -H, --hostonly Host-Only mode: Install only what is needed for
36 booting the local host instead of a generic host.
37 -i, --include [SOURCE] [TARGET]
38 Include the files in the SOURCE directory into the
39 Target directory in the final initramfs.
40 -I, --install [LIST] Install the space separated list of files into the
47 -f|
--force) force
=yes;;
48 -m|
--modules) dracutmodules_l
="$2"; shift;;
49 -o|
--omit) omit_dracutmodules_l
="$2"; shift;;
50 -a|
--add) add_dracutmodules_l
="$2"; shift;;
51 -d|
--drivers) drivers_l
="$2"; shift;;
52 -k|
--kmoddir) drivers_dir_l
="$2"; shift;;
53 -h|
--help) usage
; exit 1 ;;
54 --debug) debug
="yes";;
55 -v|
--verbose) beverbose
="yes";;
56 -c|
--conf) conffile
="$2"; shift;;
57 -l|
--local) allowlocal
="yes" ;;
58 -H|
--hostonly) hostonly
="-h" ;;
59 -i|
--include) include_src
="$2"; include_target
="$3"; shift 2;;
60 -I|
--install) install_items
="$2"; shift;;
66 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/usr
/sbin
:/usr
/bin
:/sbin
:/bin
:$PATH
69 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
73 # if we were not passed a config file, try the default one
74 [[ ! -f $conffile ]] && conffile
="/etc/dracut.conf"
76 # source our config file
77 [[ -f $conffile ]] && .
"$conffile"
79 # these options override the stuff in the config file
80 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodules_l
81 [[ $omit_dracutmodules_l ]] && omit_dracutmodules
=$omit_dracutmodules_l
82 [[ $add_dracutmodules_l ]] && add_dracutmodules
="$add_dracutmodules $add_dracutmodules_l"
83 [[ $drivers_l ]] && drivers
=$drivers_l
84 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_l
85 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/share
/dracut
87 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc
="$(dirname $0)" || dsrc
=$dracutbasedir
89 if [[ -f $dsrc/dracut-functions
]]; then
90 .
$dsrc/dracut-functions
92 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
93 echo "Try passing -l as an argument to $0"
97 dracutfunctions
=$dsrc/dracut-functions
98 export dracutfunctions
100 # This is kinda legacy -- eventually it should go away.
101 case $dracutmodules in
102 ""|auto
) dracutmodules
="all" ;;
105 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
106 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
108 if [[ -f $outfile && ! $force ]]; then
109 echo "Will not override existing initramfs ($outfile) without --force"
113 hookdirs
="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
115 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
116 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
118 # Need to be able to have non-root users read stuff (rpcbind etc)
121 export initdir hookdirs dsrc dracutmodules drivers drivers_dir debug beverbose
123 # Create some directory structure first
124 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot tmp dev
/pts var
/run
; do
125 mkdir
-p "$initdir/$d";
128 # check all our modules to see if they should be sourced.
129 # This builds a list of modules that we will install next.
133 for moddir
in "$dsrc/modules.d"/[0-9][0-9]*; do
134 mod
=${moddir##*/}; mod
=${mod#[0-9][0-9]}
135 if strstr
"$mods_to_load" " $mod "; then
137 mods_to_load
=${mods_to_load// $mod /}
143 ## final stuff that has to happen
145 # generate module dependencies for the initrd
146 if [ -d "$initdir/lib/modules/$kernel" ]; then
147 if ! depmod
-a -b "$initdir" $kernel; then
148 echo "\"depmod -a $kernel\" failed."
153 # make sure that library links are correct and up to date
154 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
156 if [[ $include_src && $include_target ]]; then
157 mkdir
-p "$initdir$include_target"
158 cp -a -t "$initdir$include_target" "$include_src"/*
161 for item
in $install_items; do
162 dracut_install
"$item"
166 [[ "$beverbose" = "yes" ]] && (du
-c "$initdir" |
sort -n)
168 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )
170 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"