]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut
add --add option to add modules to the "all" list
[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 -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
40 initramfs.
41 "
42 }
43
44 while (($# > 0)); do
45 case $1 in
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;;
59 *) break ;;
60 esac
61 shift
62 done
63
64 [[ $debug ]] && {
65 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
66 set -x
67 }
68
69 # if we were not passed a config file, try the default one
70 [[ ! -f $conffile ]] && conffile="/etc/dracut.conf"
71
72 # source our config file
73 [[ -f $conffile ]] && . "$conffile"
74
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
81
82 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir
83
84 if [[ -f $dsrc/dracut-functions ]]; then
85 . $dsrc/dracut-functions
86 else
87 echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?"
88 echo "Try passing -l as an argument to $0"
89 exit 1
90 fi
91
92 dracutfunctions=$dsrc/dracut-functions
93 export dracutfunctions
94
95 # This is kinda legacy -- eventually it should go away.
96 case $dracutmodules in
97 ""|auto) dracutmodules="all" ;;
98 esac
99
100 [[ $2 ]] && kernel=$2 || kernel=$(uname -r)
101 [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
102
103 if [[ -f $outfile && ! $force ]]; then
104 echo "Will not override existing initramfs ($outfile) without --force"
105 exit 1
106 fi
107
108 hookdirs="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency"
109
110 readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
111 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
112
113 # Need to be able to have non-root users read stuff (rpcbind etc)
114 chmod 755 "$initdir"
115
116 export initdir hookdirs dsrc dracutmodules drivers debug beverbose
117
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";
121 done
122
123 # check all our modules to see if they should be sourced.
124 # This builds a list of modules that we will install next.
125 check_modules
126
127 #source our modules.
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
131 . "$moddir/install"
132 mods_to_load=${mods_to_load// $mod /}
133 fi
134 done
135 unset moddir
136 echo $mods_to_load
137
138 ## final stuff that has to happen
139
140 # generate module dependencies for the initrd
141 if ! /sbin/depmod -a -b "$initdir" $kernel; then
142 echo "\"/sbin/depmod -a $kernel\" failed."
143 exit 1
144 fi
145
146 # make sure that library links are correct and up to date
147 ldconfig -n -r "$initdir" /lib* /usr/lib*
148
149 if [[ $include_src && $include_target ]]; then
150 mkdir -p "$initdir$include_target"
151 cp -a -t "$initdir$include_target" "$include_src"/*
152 fi
153
154 for item in $install_items; do
155 dracut_install "$item"
156 done
157 unset item
158
159 [[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n)
160
161 ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
162
163 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"
164
165 exit 0
166