]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut
fixed -c parameter handling and Makefile
[thirdparty/dracut.git] / dracut
1 #!/bin/bash
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 #
7
8 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
9 # GPLv2 header here
10
11 while (($# > 0)); do
12 case $1 in
13 -f|--force) force=yes;;
14 -m|--modules) dracutmodules_l="$2"; shift;;
15 -d|--drivers) modules_l="$2"; shift;;
16 -h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
17 exit 1 ;;
18 -v|--verbose) set -x;;
19 -c|--conf) conffile="$2"; shift;;
20 -l|--local) allowlocal="yes" ;;
21 --allow-missing) : ;;
22 *) break ;;
23 esac
24 shift
25 done
26
27 [[ -f $conffile ]] || [[ -f /etc/dracut.conf ]] && conffile="/etc/dracut.conf"
28 [[ -f $conffile ]] && . "$conffile"
29
30 [[ $dracutmodules_l ]] && dracutmodules=$dracutmodule_l
31 [[ $modules_l ]] && modules=$modules_l
32
33 [[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut
34 . $dsrc/dracut-functions
35
36 [[ $dracutmodules ]] || dracutmodules="all"
37
38 [[ $2 ]] && kernel=$2 || kernel=$(uname -r)
39 [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
40
41 if [[ -f $outfile && ! $force ]]; then
42 echo "Will not override existing initramfs ($outfile) without --force"
43 exit 1
44 fi
45
46 hookdirs="pre-udev pre-mount pre-pivot mount"
47
48 readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
49 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
50
51 export initdir hookdirs dsrc dracutmodules modules
52
53 # Create some directory structure first
54 for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
55 mkdir -p "$initdir/$d";
56 done
57
58 can_source_module() {
59 # $1 = location of module
60 mod=${1##*/}; mod=${mod#[0-9][0-9]};
61 case $dracutmodules in
62 all) return 0;;
63 auto) [[ -x $1/check ]] || return 0
64 "$1/check" >/dev/null 2>&1 && return 0 ;;
65 *) strstr "$dracutmodules" "$mod" && return 0;;
66 esac
67 return 1
68 }
69
70 # source all our modules
71 for moddir in "$dsrc/modules.d"/*; do
72 [[ -d $moddir || -L $moddir ]] || continue
73 can_source_module "$moddir" || continue
74 [[ -x $moddir/install ]] && . "$moddir/install"
75 done
76 unset moddir
77
78 ## final stuff that has to happen
79
80 # generate module dependencies for the initrd
81 /sbin/depmod -a -b "$initdir" $kernel || {
82 echo "\"/sbin/depmod -a $kernel\" failed."
83 exit 1
84 }
85
86 # make sure that library links are correct and up to date
87 ldconfig -n -r "$initdir" /lib* /usr/lib*
88
89 ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )