]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut
add --fwdir parameter to dracut
[thirdparty/dracut.git] / dracut
1 #!/bin/bash
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 #
7
8 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
9 # GPLv2 header here
10
11
12 usage() {
13 # 80x25 linebreak here ^
14 echo "Usage: $0 [OPTION]... <initramfs> <kernel-version>
15 Creates initial ramdisk images for preloading modules
16
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
27 firmwares
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
43 initramfs.
44 "
45 }
46
47 while (($# > 0)); do
48 case $1 in
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;;
64 *) break ;;
65 esac
66 shift
67 done
68
69 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
70
71 [[ $debug ]] && {
72 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
73 set -x
74 }
75
76 # if we were not passed a config file, try the default one
77 [[ ! -f $conffile ]] && conffile="/etc/dracut.conf"
78
79 # source our config file
80 [[ -f $conffile ]] && . "$conffile"
81
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
90
91 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir
92
93 if [[ -f $dsrc/dracut-functions ]]; then
94 . $dsrc/dracut-functions
95 else
96 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
97 echo "Try passing -l as an argument to $0"
98 exit 1
99 fi
100
101 dracutfunctions=$dsrc/dracut-functions
102 export dracutfunctions
103
104 # This is kinda legacy -- eventually it should go away.
105 case $dracutmodules in
106 ""|auto) dracutmodules="all" ;;
107 esac
108
109 [[ $2 ]] && kernel=$2 || kernel=$(uname -r)
110 [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
111
112 if [[ -f $outfile && ! $force ]]; then
113 echo "Will not override existing initramfs ($outfile) without --force"
114 exit 1
115 fi
116
117 hookdirs="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
118
119 readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
120 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
121
122 # Need to be able to have non-root users read stuff (rpcbind etc)
123 chmod 755 "$initdir"
124
125 export initdir hookdirs dsrc dracutmodules drivers \
126 fw_dir drivers_dir debug beverbose
127
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";
131 done
132
133 # check all our modules to see if they should be sourced.
134 # This builds a list of modules that we will install next.
135 check_modules
136
137 #source our modules.
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
141 . "$moddir/install"
142 mods_to_load=${mods_to_load// $mod /}
143 fi
144 done
145 unset moddir
146 echo $mods_to_load
147
148 ## final stuff that has to happen
149
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."
154 exit 1
155 fi
156 fi
157
158 # make sure that library links are correct and up to date
159 ldconfig -n -r "$initdir" /lib* /usr/lib*
160
161 if [[ $include_src && $include_target ]]; then
162 mkdir -p "$initdir$include_target"
163 cp -a -t "$initdir$include_target" "$include_src"/*
164 fi
165
166 for item in $install_items; do
167 dracut_install "$item"
168 done
169 unset item
170
171 [[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n)
172
173 ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
174
175 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"
176
177 exit 0
178