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