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
27 --fwdir [DIR] Specify additional directories, where to look for
28 firmwares, separated by :
29 --kernel-only Only install kernel drivers and firmware files
30 --no-kernel Do not install kernel drivers and firmware files
31 -h, --help This message
32 --debug Output debug information of the build process
33 -v, --verbose Verbose output during the build process
34 -c, --conf [FILE] Specify configuration file to use.
35 Default: /etc/dracut.conf
36 -l, --local Local mode. Use modules from the current working
37 directory instead of the system-wide installed in
38 /usr/share/dracut/modules.d.
39 Useful when running dracut from a git checkout.
40 -H, --hostonly Host-Only mode: Install only what is needed for
41 booting the local host instead of a generic host.
42 -i, --include [SOURCE] [TARGET]
43 Include the files in the SOURCE directory into the
44 Target directory in the final initramfs.
45 -I, --install [LIST] Install the space separated list of files into the
52 -f|
--force) force
=yes;;
53 -m|
--modules) dracutmodules_l
="$2"; shift;;
54 -o|
--omit) omit_dracutmodules_l
="$2"; shift;;
55 -a|
--add) add_dracutmodules_l
="$2"; shift;;
56 -d|
--drivers) drivers_l
="$2"; shift;;
57 -k|
--kmoddir) drivers_dir_l
="$2"; shift;;
58 --fwdir) fw_dir_l
="$2"; shift;;
59 --kernel-only) kernel_only
="yes"; nokernel
="no";;
60 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
61 -h|
--help) usage
; exit 1 ;;
62 --debug) debug
="yes";;
63 -v|
--verbose) beverbose
="yes";;
64 -c|
--conf) conffile
="$2"; shift;;
65 -l|
--local) allowlocal
="yes" ;;
66 -H|
--hostonly) hostonly
="-h" ;;
67 -i|
--include) include_src
="$2"; include_target
="$3"; shift 2;;
68 -I|
--install) install_items
="$2"; shift;;
69 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage
; exit 1;;
75 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/usr
/sbin
:/usr
/bin
:/sbin
:/bin
:$PATH
78 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
82 # if we were not passed a config file, try the default one
83 [[ ! -f $conffile ]] && conffile
="/etc/dracut.conf"
85 # source our config file
86 [[ -f $conffile ]] && .
"$conffile"
88 # these options override the stuff in the config file
89 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodules_l
90 [[ $omit_dracutmodules_l ]] && omit_dracutmodules
=$omit_dracutmodules_l
91 [[ $add_dracutmodules_l ]] && add_dracutmodules
="$add_dracutmodules $add_dracutmodules_l"
92 [[ $drivers_l ]] && drivers
=$drivers_l
93 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
94 [[ $fw_dir_l ]] && fw_dir
=$fw_dir_l
95 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/share
/dracut
96 [[ $fw_dir ]] || fw_dir
=/lib
/firmware
98 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc
="$(dirname $0)" || dsrc
=$dracutbasedir
100 if [[ -f $dsrc/dracut-functions
]]; then
101 .
$dsrc/dracut-functions
103 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
104 echo "Try passing -l as an argument to $0"
108 dracutfunctions
=$dsrc/dracut-functions
109 export dracutfunctions
111 # This is kinda legacy -- eventually it should go away.
112 case $dracutmodules in
113 ""|auto
) dracutmodules
="all" ;;
116 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
117 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
119 srcmods
="/lib/modules/$kernel/"
120 [ -n "$drivers_dir" ] && srcmods
="$drivers_dir"
123 if [[ -f $outfile && ! $force ]]; then
124 echo "Will not override existing initramfs ($outfile) without --force"
128 hookdirs
="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
130 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
131 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
133 # Need to be able to have non-root users read stuff (rpcbind etc)
136 export initdir hookdirs dsrc dracutmodules drivers \
137 fw_dir drivers_dir debug beverbose no_kernel kernel_only
139 if [[ "$kernel_only" != "yes" ]]; then
140 # Create some directory structure first
141 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot tmp dev
/pts var
/run
; do
142 mkdir
-p "$initdir/$d";
146 # check all our modules to see if they should be sourced.
147 # This builds a list of modules that we will install next.
151 for moddir
in "$dsrc/modules.d"/[0-9][0-9]*; do
152 mod
=${moddir##*/}; mod
=${mod#[0-9][0-9]}
153 if strstr
"$mods_to_load" " $mod "; then
154 if [[ "$kernel_only" = "yes" ]]; then
155 [[ -x "$moddir/installkernel" ]] && .
"$moddir/installkernel"
158 if [[ "$no_kernel" != "yes" && -x "$moddir/installkernel" ]]; then
159 .
"$moddir/installkernel"
162 mods_to_load
=${mods_to_load// $mod /}
168 ## final stuff that has to happen
170 # generate module dependencies for the initrd
171 if [ -d "$initdir/lib/modules/$kernel" ]; then
172 if ! depmod
-a -b "$initdir" $kernel; then
173 echo "\"depmod -a $kernel\" failed."
178 # make sure that library links are correct and up to date
179 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
181 if [[ $include_src && $include_target ]]; then
182 mkdir
-p "$initdir$include_target"
183 cp -a -t "$initdir$include_target" "$include_src"/*
186 for item
in $install_items; do
187 dracut_install
"$item"
191 [[ "$beverbose" = "yes" ]] && (du
-c "$initdir" |
sort -n)
193 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )
195 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"