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