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