]>
Commit | Line | Data |
---|---|---|
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 | |
641cc356 JK |
8 | # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com> |
9 | # GPLv2 header here | |
ec9315e5 | 10 | |
5616feb0 AT |
11 | |
12 | usage() { | |
13 | # 80x25 linebreak here ^ | |
14 | echo "Usage: $0 [OPTION]... <initramfs> <kernel-version> | |
15 | Creates initial ramdisk images for preloading modules | |
16 | ||
39ff0682 | 17 | -f, --force Overwrite existing initramfs file. |
5616feb0 AT |
18 | -m, --modules [LIST] Specify a space-separated list of dracut modules to |
19 | call when building the initramfs. Modules are located | |
39ff0682 AT |
20 | in /usr/lib/dracut/modules.d. |
21 | -o, --omit [LIST] Omit a space-separated list of dracut modules. | |
5616feb0 | 22 | -d, --drivers [LIST] Specify a space-separated list of kernel modules to |
39ff0682 | 23 | include in the initramfs. |
5616feb0 | 24 | -h, --help This message |
00531568 | 25 | --debug Output debug information of the build process |
5616feb0 AT |
26 | -v, --verbose Verbose output during the build process |
27 | -c, --conf [FILE] Specify configuration file to use. | |
28 | Default: /etc/dracut.conf | |
29 | -l, --local Local mode. Use modules from the current working | |
30 | directory instead of the system-wide installed in | |
31 | /usr/lib/dracut/modules.d. | |
32 | Useful when running dracut from a git checkout. | |
39ff0682 | 33 | -H, --hostonly Host-Only mode: Install only what is needed for |
5616feb0 AT |
34 | booting the local host instead of a generic host. |
35 | -i, --include [SOURCE] [TARGET] | |
39ff0682 AT |
36 | Include the files in the SOURCE directory into the |
37 | Target directory in the final initramfs. | |
38 | -I, --install [LIST] Install the space separated list of files into the | |
39 | initramfs. | |
40 | --skip-missing Do not quit on missing module dependencies but skip | |
41 | these. | |
5616feb0 AT |
42 | " |
43 | } | |
44 | ||
b368a5f3 | 45 | while (($# > 0)); do |
641cc356 | 46 | case $1 in |
b368a5f3 | 47 | -f|--force) force=yes;; |
4cba351e | 48 | -m|--modules) dracutmodules_l="$2"; shift;; |
3274a8f9 | 49 | -o|--omit) omit_dracutmodules_l="$2"; shift;; |
4cba351e | 50 | -d|--drivers) modules_l="$2"; shift;; |
5616feb0 | 51 | -h|--help) usage; exit 1 ;; |
00531568 | 52 | --debug) debug="yes"; set -x;; |
c4ad7fff | 53 | -v|--verbose) beverbose="yes";; |
af2ac891 | 54 | -c|--conf) conffile="$2"; shift;; |
b368a5f3 | 55 | -l|--local) allowlocal="yes" ;; |
39ff0682 | 56 | -H|--hostonly) hostonly="-h" ;; |
88ffd2df | 57 | -i|--include) include_src="$2"; include_target="$3"; shift 2;; |
39ff0682 | 58 | -I|--install) install_items="$2"; shift;; |
ba5433e9 | 59 | --skip-missing) skipmissing="yes" ;; |
b368a5f3 | 60 | *) break ;; |
641cc356 | 61 | esac |
b368a5f3 | 62 | shift |
641cc356 | 63 | done |
4cba351e | 64 | |
6722a717 | 65 | [[ -f $conffile ]] || { [[ -f /etc/dracut.conf ]] && conffile="/etc/dracut.conf" } |
4cba351e | 66 | [[ -f $conffile ]] && . "$conffile" |
e12aac5e | 67 | [[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l |
3274a8f9 | 68 | [[ $omit_dracutmodules_l ]] && omit_dracutmodules=$omit_dracutmodules_l |
4cba351e | 69 | [[ $modules_l ]] && modules=$modules_l |
9a8a00cf VL |
70 | |
71 | [[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut | |
adbc8a42 AT |
72 | if [[ -f $dsrc/dracut-functions ]]; then |
73 | . $dsrc/dracut-functions | |
74 | else | |
75 | echo "Cannot find dracut-functions. Are you running from a git checkout?" | |
76 | echo "Try passing -l as an argument to $0" | |
77 | exit 1 | |
78 | fi | |
5cad5bb5 HH |
79 | dracutfunctions=$dsrc/dracut-functions |
80 | export dracutfunctions | |
9a8a00cf | 81 | |
7f8205e1 | 82 | [[ $dracutmodules ]] || dracutmodules="auto" |
ba5433e9 PS |
83 | [[ $dracutmodules = "auto" ]] && { |
84 | dracutmodules="all" | |
85 | skipmissing="yes" | |
86 | } | |
5cad5bb5 HH |
87 | [[ $dracutmodules = "hostonly" ]] && { |
88 | dracutmodules="all" | |
89 | skipmissing="yes" | |
90 | hostonly="-h" | |
91 | } | |
e12aac5e | 92 | |
71388098 | 93 | |
c8937ec4 | 94 | [[ $2 ]] && kernel=$2 || kernel=$(uname -r) |
95994c57 | 95 | [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img" |
ec9315e5 | 96 | |
c8937ec4 | 97 | if [[ -f $outfile && ! $force ]]; then |
641cc356 | 98 | echo "Will not override existing initramfs ($outfile) without --force" |
ec9315e5 JK |
99 | exit 1 |
100 | fi | |
101 | ||
a4aee9e5 | 102 | hookdirs="pre-udev pre-mount pre-pivot mount emergency" |
49c68fa4 VL |
103 | |
104 | readonly initdir=$(mktemp -d -t initramfs.XXXXXX) | |
2c6fc388 | 105 | trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die. |
ec9315e5 | 106 | |
84ffb877 | 107 | export initdir hookdirs dsrc dracutmodules modules debug beverbose |
f4fff04e | 108 | |
0f86847d VL |
109 | # Create some directory structure first |
110 | for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do | |
111 | mkdir -p "$initdir/$d"; | |
112 | done | |
113 | ||
71388098 VL |
114 | skip_missing() { |
115 | # $1 = location of module | |
116 | [[ $skipmissing ]] || return 0 | |
117 | [[ -x $1/check ]] || return 0 | |
118 | "$1/check" $hostonly | |
119 | } | |
120 | ||
8d02da42 VL |
121 | can_source_module() { |
122 | # $1 = location of module | |
123 | mod=${1##*/}; mod=${mod#[0-9][0-9]}; | |
71388098 | 124 | if [[ $dracutmodules != all ]]; then |
7f8205e1 | 125 | strstr "$dracutmodules " "$mod " || return 1 |
71388098 | 126 | fi |
3274a8f9 | 127 | strstr "$omit_dracutmodules " "$mod " && return 1 |
71388098 | 128 | skip_missing "$1" |
8d02da42 VL |
129 | } |
130 | ||
f04dc5f3 | 131 | # source all our modules |
20abd914 VL |
132 | for moddir in "$dsrc/modules.d"/*; do |
133 | [[ -d $moddir || -L $moddir ]] || continue | |
8d02da42 VL |
134 | can_source_module "$moddir" || continue |
135 | [[ -x $moddir/install ]] && . "$moddir/install" | |
15136762 | 136 | done |
20abd914 | 137 | unset moddir |
aabc0553 | 138 | |
0f86847d | 139 | ## final stuff that has to happen |
bc6b0dec | 140 | |
0f86847d | 141 | # generate module dependencies for the initrd |
3c3e1e0c | 142 | /sbin/depmod -a -b "$initdir" $kernel || { |
3f746592 | 143 | echo "\"/sbin/depmod -a $kernel\" failed." |
641cc356 | 144 | exit 1 |
3c3e1e0c | 145 | } |
ec9315e5 | 146 | |
0f86847d | 147 | # make sure that library links are correct and up to date |
7702658f | 148 | ldconfig -n -r "$initdir" /lib* /usr/lib* |
0f86847d | 149 | |
88ffd2df VL |
150 | [[ $include_src && $include_target ]] && { |
151 | mkdir -p "$initdir$include_target" | |
152 | cp -a -t "$initdir$include_target" "$include_src"/* | |
153 | } | |
154 | ||
39ff0682 AT |
155 | for item in $install_items; do |
156 | dracut_install "$item" | |
157 | done | |
158 | unset item | |
159 | ||
c4ad7fff HH |
160 | [[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n) |
161 | ||
3c3e1e0c | 162 | ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; ) |
c4ad7fff HH |
163 | |
164 | [[ "$beverbose" = "yes" ]] && ls -lh "$outfile" | |
165 | ||
166 | : |