]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
let find_rule find absolute path rules
[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
641cc356
JK
8# Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
9# GPLv2 header here
ec9315e5 10
5616feb0
AT
11
12usage() {
13# 80x25 linebreak here ^
14 echo "Usage: $0 [OPTION]... <initramfs> <kernel-version>
15Creates 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 45while (($# > 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 63done
4cba351e 64
f1336ac7
VL
65# if we were not passed a config file, try the default one
66[[ ! -f $conffile ]] && conffile="/etc/dracut.conf"
67
68# source our config file
4cba351e 69[[ -f $conffile ]] && . "$conffile"
f1336ac7
VL
70
71# these options override the stuff in the config file
e12aac5e 72[[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l
3274a8f9 73[[ $omit_dracutmodules_l ]] && omit_dracutmodules=$omit_dracutmodules_l
4cba351e 74[[ $modules_l ]] && modules=$modules_l
9a8a00cf
VL
75
76[[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut
adbc8a42
AT
77if [[ -f $dsrc/dracut-functions ]]; then
78 . $dsrc/dracut-functions
79else
80 echo "Cannot find dracut-functions. Are you running from a git checkout?"
81 echo "Try passing -l as an argument to $0"
82 exit 1
83fi
5cad5bb5
HH
84dracutfunctions=$dsrc/dracut-functions
85export dracutfunctions
9a8a00cf 86
f1336ac7
VL
87# this logic is weird and convoluted. We should simplify it.
88case $dracutmodules in
89 ""|auto)
90 dracutmodules="all"
91 skipmissing="yes"
92 ;;
93 hostonly)
94 dracutmodules="all"
95 skipmissing="yes"
96 hostonly="-h"
97 ;;
98esac
e12aac5e 99
71388098 100
c8937ec4 101[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
95994c57 102[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
ec9315e5 103
c8937ec4 104if [[ -f $outfile && ! $force ]]; then
641cc356 105 echo "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
106 exit 1
107fi
108
a4aee9e5 109hookdirs="pre-udev pre-mount pre-pivot mount emergency"
49c68fa4
VL
110
111readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
2c6fc388 112trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
ec9315e5 113
f6f74096
DD
114# Need to be able to have non-root users read stuff (rpcbind etc)
115chmod 755 "$initdir"
116
84ffb877 117export initdir hookdirs dsrc dracutmodules modules debug beverbose
f4fff04e 118
0f86847d 119# Create some directory structure first
f6f74096 120for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts var/run; do
0f86847d
VL
121 mkdir -p "$initdir/$d";
122done
123
f1336ac7
VL
124# these bits are fugly, and need some cleanup.
125# Actually documenting how dracut modules work these days would be good.
71388098
VL
126skip_missing() {
127 # $1 = location of module
128 [[ $skipmissing ]] || return 0
129 [[ -x $1/check ]] || return 0
130 "$1/check" $hostonly
131}
132
8d02da42
VL
133can_source_module() {
134 # $1 = location of module
135 mod=${1##*/}; mod=${mod#[0-9][0-9]};
71388098 136 if [[ $dracutmodules != all ]]; then
7f8205e1 137 strstr "$dracutmodules " "$mod " || return 1
71388098 138 fi
3274a8f9 139 strstr "$omit_dracutmodules " "$mod " && return 1
71388098 140 skip_missing "$1"
8d02da42
VL
141}
142
f04dc5f3 143# source all our modules
20abd914
VL
144for moddir in "$dsrc/modules.d"/*; do
145 [[ -d $moddir || -L $moddir ]] || continue
8d02da42
VL
146 can_source_module "$moddir" || continue
147 [[ -x $moddir/install ]] && . "$moddir/install"
15136762 148done
20abd914 149unset moddir
aabc0553 150
0f86847d 151## final stuff that has to happen
bc6b0dec 152
0f86847d 153# generate module dependencies for the initrd
f1336ac7 154if ! /sbin/depmod -a -b "$initdir" $kernel; then
3f746592 155 echo "\"/sbin/depmod -a $kernel\" failed."
641cc356 156 exit 1
f1336ac7 157fi
ec9315e5 158
0f86847d 159# make sure that library links are correct and up to date
7702658f 160ldconfig -n -r "$initdir" /lib* /usr/lib*
0f86847d 161
f1336ac7 162if [[ $include_src && $include_target ]]; then
88ffd2df
VL
163 mkdir -p "$initdir$include_target"
164 cp -a -t "$initdir$include_target" "$include_src"/*
f1336ac7 165fi
88ffd2df 166
39ff0682
AT
167for item in $install_items; do
168 dracut_install "$item"
169done
170unset item
171
c4ad7fff
HH
172[[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n)
173
3c3e1e0c 174( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
c4ad7fff
HH
175
176[[ "$beverbose" = "yes" ]] && ls -lh "$outfile"
177
178: