]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
dmraid: do not fail if /usr/lib/libdmraid-events-isw.so is not present
[thirdparty/dracut.git] / dracut
CommitLineData
c0815e4e 1#!/bin/bash
641cc356
JK
2#
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
6#
70c26b7f 7
4f18fe82
HH
8# Copyright 2005-2009 Red Hat, Inc. All rights reserved.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
ec9315e5 23
5616feb0
AT
24
25usage() {
26# 80x25 linebreak here ^
27 echo "Usage: $0 [OPTION]... <initramfs> <kernel-version>
28Creates initial ramdisk images for preloading modules
29
39ff0682 30 -f, --force Overwrite existing initramfs file.
5616feb0
AT
31 -m, --modules [LIST] Specify a space-separated list of dracut modules to
32 call when building the initramfs. Modules are located
73198d53 33 in /usr/share/dracut/modules.d.
39ff0682 34 -o, --omit [LIST] Omit a space-separated list of dracut modules.
3e17f33b 35 -a, --add [LIST] Add a space-separated list of dracut modules.
5616feb0 36 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
cb47caf7
HH
37 exclusively include in the initramfs.
38 --add-drivers [LIST] Specify a space-separated list of kernel
39 modules to add to the initramfs.
2b9dfbbe
HH
40 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
41 modules
33ee031c
HH
42 --fwdir [DIR] Specify additional directories, where to look for
43 firmwares, separated by :
44 --kernel-only Only install kernel drivers and firmware files
45 --no-kernel Do not install kernel drivers and firmware files
31f7db66
HH
46 --strip Strip binaries in the initramfs (default)
47 --nostrip Do not strip binaries in the initramfs
2f02ae9d
HH
48 --mdadmconf Include local /etc/mdadm.conf
49 --nomdadmconf Do not include local /etc/mdadm.conf
7a34efa5
HH
50 --lvmconf Include local /etc/lvm/lvm.conf
51 --nolvmconf Do not include local /etc/lvm/lvm.conf
5616feb0 52 -h, --help This message
00531568 53 --debug Output debug information of the build process
5616feb0
AT
54 -v, --verbose Verbose output during the build process
55 -c, --conf [FILE] Specify configuration file to use.
56 Default: /etc/dracut.conf
57 -l, --local Local mode. Use modules from the current working
58 directory instead of the system-wide installed in
73198d53 59 /usr/share/dracut/modules.d.
5616feb0 60 Useful when running dracut from a git checkout.
39ff0682 61 -H, --hostonly Host-Only mode: Install only what is needed for
5616feb0
AT
62 booting the local host instead of a generic host.
63 -i, --include [SOURCE] [TARGET]
39ff0682
AT
64 Include the files in the SOURCE directory into the
65 Target directory in the final initramfs.
66 -I, --install [LIST] Install the space separated list of files into the
67 initramfs.
5616feb0
AT
68"
69}
70
b368a5f3 71while (($# > 0)); do
641cc356 72 case $1 in
b368a5f3 73 -f|--force) force=yes;;
4cba351e 74 -m|--modules) dracutmodules_l="$2"; shift;;
3274a8f9 75 -o|--omit) omit_dracutmodules_l="$2"; shift;;
3e17f33b 76 -a|--add) add_dracutmodules_l="$2"; shift;;
e19d6bf6 77 -d|--drivers) drivers_l="$2"; shift;;
cb47caf7 78 --add-drivers) add_drivers_l="$2"; shift;;
04db5fdc 79 -k|--kmoddir) drivers_dir_l="$2"; shift;;
26537a5b 80 --fwdir) fw_dir_l="$2"; shift;;
33ee031c
HH
81 --kernel-only) kernel_only="yes"; nokernel="no";;
82 --no-kernel) kernel_only="no"; no_kernel="yes";;
31f7db66
HH
83 --strip) do_strip_l="yes";;
84 --nostrip) do_strip_l="no";;
2f02ae9d
HH
85 --mdadmconf) mdadmconf_l="yes";;
86 --nomdadmconf) mdadmconf_l="no";;
7a34efa5
HH
87 --lvmconf) lvmconf_l="yes";;
88 --nolvmconf) lvmconf_l="no";;
5616feb0 89 -h|--help) usage; exit 1 ;;
c36ce334 90 --debug) debug="yes";;
c4ad7fff 91 -v|--verbose) beverbose="yes";;
af2ac891 92 -c|--conf) conffile="$2"; shift;;
b368a5f3 93 -l|--local) allowlocal="yes" ;;
ba726310 94 -H|--hostonly) hostonly_l="yes" ;;
88ffd2df 95 -i|--include) include_src="$2"; include_target="$3"; shift 2;;
39ff0682 96 -I|--install) install_items="$2"; shift;;
13beb248 97 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
b368a5f3 98 *) break ;;
641cc356 99 esac
b368a5f3 100 shift
641cc356 101done
4cba351e 102
f8545d04
HH
103PATH=/sbin:/bin:/usr/sbin:/usr/bin
104export PATH
a55711cd 105
c36ce334
VL
106[[ $debug ]] && {
107 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
108 set -x
109}
110
f1336ac7
VL
111# if we were not passed a config file, try the default one
112[[ ! -f $conffile ]] && conffile="/etc/dracut.conf"
113
114# source our config file
4cba351e 115[[ -f $conffile ]] && . "$conffile"
f1336ac7
VL
116
117# these options override the stuff in the config file
e12aac5e 118[[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l
3274a8f9 119[[ $omit_dracutmodules_l ]] && omit_dracutmodules=$omit_dracutmodules_l
3e17f33b 120[[ $add_dracutmodules_l ]] && add_dracutmodules="$add_dracutmodules $add_dracutmodules_l"
e19d6bf6 121[[ $drivers_l ]] && drivers=$drivers_l
cb47caf7 122[[ $add_drivers_l ]] && add_drivers=$add_drivers_l
26537a5b
HH
123[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
124[[ $fw_dir_l ]] && fw_dir=$fw_dir_l
31f7db66 125[[ $do_strip_l ]] && do_strip=$do_strip_l
ba726310 126[[ $hostonly_l ]] && hostonly=$hostonly_l
2f02ae9d 127[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
7a34efa5 128[[ $lvmconf_l ]] && lvmconf=$lvmconf_l
73198d53 129[[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
33ee031c 130[[ $fw_dir ]] || fw_dir=/lib/firmware
31f7db66 131[[ $do_strip ]] || do_strip=yes
ddfd1d10
VL
132# eliminate IFS hackery when messing with fw_dir
133fw_dir=${fw_dir//:/ }
9a8a00cf 134
ba726310
HH
135[[ $hostonly = yes ]] && hostonly="-h"
136
fc3c64c8 137[[ $allowlocal && -f "$(readlink -f $(dirname $0))/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir
1a918b40 138
adbc8a42
AT
139if [[ -f $dsrc/dracut-functions ]]; then
140 . $dsrc/dracut-functions
141else
22fd1627 142 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
adbc8a42
AT
143 echo "Try passing -l as an argument to $0"
144 exit 1
145fi
22fd1627 146
5cad5bb5
HH
147dracutfunctions=$dsrc/dracut-functions
148export dracutfunctions
9a8a00cf 149
66ac3cd1 150# This is kinda legacy -- eventually it should go away.
f1336ac7 151case $dracutmodules in
66ac3cd1 152 ""|auto) dracutmodules="all" ;;
f1336ac7 153esac
e12aac5e 154
c8937ec4 155[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
95994c57 156[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
ec9315e5 157
f24a2d46 158srcmods="/lib/modules/$kernel/"
0b90cfaa 159[[ $drivers_dir ]] && srcmods="$drivers_dir"
f24a2d46
HH
160export srcmods
161
c8937ec4 162if [[ -f $outfile && ! $force ]]; then
641cc356 163 echo "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
164 exit 1
165fi
166
1eeddd31 167hookdirs="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
49c68fa4
VL
168
169readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
5af0cf0c
HH
170trap 'ret=$?;rm -rf "$initdir";exit $ret;' EXIT # clean up after ourselves no matter how we die.
171trap 'exit 1;' SIGINT # clean up after ourselves no matter how we die.
ec9315e5 172
f6f74096
DD
173# Need to be able to have non-root users read stuff (rpcbind etc)
174chmod 755 "$initdir"
175
26537a5b 176export initdir hookdirs dsrc dracutmodules drivers \
cb47caf7 177 fw_dir drivers_dir debug beverbose no_kernel kernel_only \
7a34efa5 178 add_drivers mdadmconf lvmconf
f4fff04e 179
98adb06e 180if [[ $kernel_only != yes ]]; then
33ee031c
HH
181 # Create some directory structure first
182 for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot tmp dev/pts var/run; do
19612483 183 inst_dir "/$d";
33ee031c
HH
184 done
185fi
0f86847d 186
66ac3cd1
VL
187# check all our modules to see if they should be sourced.
188# This builds a list of modules that we will install next.
0c2e3d12
VL
189check_modules
190
191#source our modules.
192for moddir in "$dsrc/modules.d"/[0-9][0-9]*; do
193 mod=${moddir##*/}; mod=${mod#[0-9][0-9]}
66ac3cd1 194 if strstr "$mods_to_load" " $mod "; then
98adb06e
VL
195 if [[ $kernel_only = yes ]]; then
196 [[ -x $moddir/installkernel ]] && . "$moddir/installkernel"
33ee031c
HH
197 else
198 . "$moddir/install"
98adb06e 199 if [[ $no_kernel != yes && -x $moddir/installkernel ]]; then
33ee031c
HH
200 . "$moddir/installkernel"
201 fi
202 fi
66ac3cd1
VL
203 mods_to_load=${mods_to_load// $mod /}
204 fi
15136762 205done
20abd914 206unset moddir
aabc0553 207
0f86847d 208## final stuff that has to happen
bc6b0dec 209
0f86847d 210# generate module dependencies for the initrd
98adb06e 211if [[ -d $initdir/lib/modules/$kernel ]]; then
1b9cae5c
DD
212 if ! depmod -a -b "$initdir" $kernel; then
213 echo "\"depmod -a $kernel\" failed."
214 exit 1
215 fi
f1336ac7 216fi
ec9315e5 217
0f86847d 218# make sure that library links are correct and up to date
7702658f 219ldconfig -n -r "$initdir" /lib* /usr/lib*
0f86847d 220
f1336ac7 221if [[ $include_src && $include_target ]]; then
88ffd2df
VL
222 mkdir -p "$initdir$include_target"
223 cp -a -t "$initdir$include_target" "$include_src"/*
f1336ac7 224fi
88ffd2df 225
39ff0682
AT
226for item in $install_items; do
227 dracut_install "$item"
228done
229unset item
230
98adb06e 231[[ $beverbose = yes ]] && (du -c "$initdir" | sort -n)
c4ad7fff 232
31f7db66 233# strip binaries
98adb06e 234if [[ $do_strip = yes ]] ; then
31f7db66
HH
235 for p in strip objdump sed grep find; do
236 if ! which $p >/dev/null 2>&1; then
237 derror "Could not find '$p'. You should run $0 with '--nostrip'."
238 do_strip=no
239 fi
240 done
241fi
242
98adb06e 243if [[ $do_strip = yes ]] ; then
34debf18 244 for f in $(find "$initdir" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 -or -path '/lib/modules/*.ko' \) -exec file {} \; |
31f7db66
HH
245 grep -v ' shared object,' |
246 sed -n -e 's/^\(.*\):[ ]*ELF.*, not stripped/\1/p'); do
247 dinfo "Stripping $f"
248 strip -g "$f" || :
249 #
250 # FIXME: only strip -g for now
251 #
252 #strip -g --strip-unneeded "$f" || :
253 #note="-R .note"
254 #if objdump -h $f | grep '^[ ]*[0-9]*[ ]*.note[ ]' -A 1 | \
255 # grep -q ALLOC; then
256 # note=
257 #fi
258 #strip -R .comment $note "$f" || :
259 done
260fi
261
bf84ee3c 262( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet |gzip -9 > "$outfile"; )
c4ad7fff 263
98adb06e 264[[ $beverbose = yes ]] && ls -lh "$outfile"
1faecdc1 265
3da58569
WT
266exit 0
267