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