]>
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 | |
73198d53 | 20 | in /usr/share/dracut/modules.d. |
39ff0682 | 21 | -o, --omit [LIST] Omit a space-separated list of dracut modules. |
3e17f33b | 22 | -a, --add [LIST] Add a space-separated list of dracut modules. |
5616feb0 | 23 | -d, --drivers [LIST] Specify a space-separated list of kernel modules to |
39ff0682 | 24 | include in the initramfs. |
5616feb0 | 25 | -h, --help This message |
00531568 | 26 | --debug Output debug information of the build process |
5616feb0 AT |
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 | |
73198d53 | 32 | /usr/share/dracut/modules.d. |
5616feb0 | 33 | Useful when running dracut from a git checkout. |
39ff0682 | 34 | -H, --hostonly Host-Only mode: Install only what is needed for |
5616feb0 AT |
35 | booting the local host instead of a generic host. |
36 | -i, --include [SOURCE] [TARGET] | |
39ff0682 AT |
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. | |
5616feb0 AT |
41 | " |
42 | } | |
43 | ||
b368a5f3 | 44 | while (($# > 0)); do |
641cc356 | 45 | case $1 in |
b368a5f3 | 46 | -f|--force) force=yes;; |
4cba351e | 47 | -m|--modules) dracutmodules_l="$2"; shift;; |
3274a8f9 | 48 | -o|--omit) omit_dracutmodules_l="$2"; shift;; |
3e17f33b | 49 | -a|--add) add_dracutmodules_l="$2"; shift;; |
e19d6bf6 | 50 | -d|--drivers) drivers_l="$2"; shift;; |
5616feb0 | 51 | -h|--help) usage; exit 1 ;; |
c36ce334 | 52 | --debug) debug="yes";; |
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;; |
b368a5f3 | 59 | *) break ;; |
641cc356 | 60 | esac |
b368a5f3 | 61 | shift |
641cc356 | 62 | done |
4cba351e | 63 | |
a55711cd PS |
64 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH |
65 | ||
c36ce334 VL |
66 | [[ $debug ]] && { |
67 | export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '; | |
68 | set -x | |
69 | } | |
70 | ||
f1336ac7 VL |
71 | # if we were not passed a config file, try the default one |
72 | [[ ! -f $conffile ]] && conffile="/etc/dracut.conf" | |
73 | ||
74 | # source our config file | |
4cba351e | 75 | [[ -f $conffile ]] && . "$conffile" |
f1336ac7 VL |
76 | |
77 | # these options override the stuff in the config file | |
e12aac5e | 78 | [[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l |
3274a8f9 | 79 | [[ $omit_dracutmodules_l ]] && omit_dracutmodules=$omit_dracutmodules_l |
3e17f33b | 80 | [[ $add_dracutmodules_l ]] && add_dracutmodules="$add_dracutmodules $add_dracutmodules_l" |
e19d6bf6 | 81 | [[ $drivers_l ]] && drivers=$drivers_l |
73198d53 | 82 | [[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut |
9a8a00cf | 83 | |
56d8568c | 84 | [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir |
1a918b40 | 85 | |
adbc8a42 AT |
86 | if [[ -f $dsrc/dracut-functions ]]; then |
87 | . $dsrc/dracut-functions | |
88 | else | |
22fd1627 | 89 | echo "Cannot find $dsrc/dracut-functions. Are you running from a git checkout?" |
adbc8a42 AT |
90 | echo "Try passing -l as an argument to $0" |
91 | exit 1 | |
92 | fi | |
22fd1627 | 93 | |
5cad5bb5 HH |
94 | dracutfunctions=$dsrc/dracut-functions |
95 | export dracutfunctions | |
9a8a00cf | 96 | |
66ac3cd1 | 97 | # This is kinda legacy -- eventually it should go away. |
f1336ac7 | 98 | case $dracutmodules in |
66ac3cd1 | 99 | ""|auto) dracutmodules="all" ;; |
f1336ac7 | 100 | esac |
e12aac5e | 101 | |
c8937ec4 | 102 | [[ $2 ]] && kernel=$2 || kernel=$(uname -r) |
95994c57 | 103 | [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img" |
ec9315e5 | 104 | |
c8937ec4 | 105 | if [[ -f $outfile && ! $force ]]; then |
641cc356 | 106 | echo "Will not override existing initramfs ($outfile) without --force" |
ec9315e5 JK |
107 | exit 1 |
108 | fi | |
109 | ||
1eeddd31 | 110 | hookdirs="cmdline pre-udev pre-trigger netroot pre-mount pre-pivot mount emergency" |
49c68fa4 VL |
111 | |
112 | readonly initdir=$(mktemp -d -t initramfs.XXXXXX) | |
2c6fc388 | 113 | trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die. |
ec9315e5 | 114 | |
f6f74096 DD |
115 | # Need to be able to have non-root users read stuff (rpcbind etc) |
116 | chmod 755 "$initdir" | |
117 | ||
e19d6bf6 | 118 | export initdir hookdirs dsrc dracutmodules drivers debug beverbose |
f4fff04e | 119 | |
0f86847d | 120 | # Create some directory structure first |
3da58569 | 121 | for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot tmp dev/pts var/run; do |
0f86847d VL |
122 | mkdir -p "$initdir/$d"; |
123 | done | |
124 | ||
66ac3cd1 VL |
125 | # check all our modules to see if they should be sourced. |
126 | # This builds a list of modules that we will install next. | |
0c2e3d12 VL |
127 | check_modules |
128 | ||
129 | #source our modules. | |
130 | for moddir in "$dsrc/modules.d"/[0-9][0-9]*; do | |
131 | mod=${moddir##*/}; mod=${mod#[0-9][0-9]} | |
66ac3cd1 VL |
132 | if strstr "$mods_to_load" " $mod "; then |
133 | . "$moddir/install" | |
134 | mods_to_load=${mods_to_load// $mod /} | |
135 | fi | |
15136762 | 136 | done |
20abd914 | 137 | unset moddir |
66ac3cd1 | 138 | echo $mods_to_load |
aabc0553 | 139 | |
0f86847d | 140 | ## final stuff that has to happen |
bc6b0dec | 141 | |
0f86847d | 142 | # generate module dependencies for the initrd |
a55711cd PS |
143 | if ! depmod -a -b "$initdir" $kernel; then |
144 | echo "\"depmod -a $kernel\" failed." | |
641cc356 | 145 | exit 1 |
f1336ac7 | 146 | fi |
ec9315e5 | 147 | |
0f86847d | 148 | # make sure that library links are correct and up to date |
7702658f | 149 | ldconfig -n -r "$initdir" /lib* /usr/lib* |
0f86847d | 150 | |
f1336ac7 | 151 | if [[ $include_src && $include_target ]]; then |
88ffd2df VL |
152 | mkdir -p "$initdir$include_target" |
153 | cp -a -t "$initdir$include_target" "$include_src"/* | |
f1336ac7 | 154 | fi |
88ffd2df | 155 | |
39ff0682 AT |
156 | for item in $install_items; do |
157 | dracut_install "$item" | |
158 | done | |
159 | unset item | |
160 | ||
c4ad7fff HH |
161 | [[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n) |
162 | ||
3c3e1e0c | 163 | ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; ) |
c4ad7fff HH |
164 | |
165 | [[ "$beverbose" = "yes" ]] && ls -lh "$outfile" | |
1faecdc1 | 166 | |
3da58569 WT |
167 | exit 0 |
168 |