]>
Commit | Line | Data |
---|---|---|
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 | |
b368a5f3 | 11 | while (($# > 0)); do |
641cc356 | 12 | case $1 in |
b368a5f3 | 13 | -f|--force) force=yes;; |
4cba351e PS |
14 | -m|--modules) dracutmodules_l="$2"; shift;; |
15 | -d|--drivers) modules_l="$2"; shift;; | |
b368a5f3 VL |
16 | -h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>" |
17 | exit 1 ;; | |
18 | -v|--verbose) set -x;; | |
af2ac891 | 19 | -c|--conf) conffile="$2"; shift;; |
b368a5f3 | 20 | -l|--local) allowlocal="yes" ;; |
ba5433e9 | 21 | --skip-missing) skipmissing="yes" ;; |
b368a5f3 | 22 | *) break ;; |
641cc356 | 23 | esac |
b368a5f3 | 24 | shift |
641cc356 | 25 | done |
4cba351e | 26 | |
e12aac5e | 27 | [[ -f $conffile ]] || ( [[ -f /etc/dracut.conf ]] && conffile="/etc/dracut.conf" ) |
4cba351e | 28 | [[ -f $conffile ]] && . "$conffile" |
e12aac5e | 29 | [[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l |
4cba351e | 30 | [[ $modules_l ]] && modules=$modules_l |
9a8a00cf VL |
31 | |
32 | [[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut | |
33 | . $dsrc/dracut-functions | |
34 | ||
ba5433e9 PS |
35 | [[ $dracutmodules ]] || dracutmodules="auto" |
36 | [[ $dracutmodules = "auto" ]] && { | |
37 | dracutmodules="all" | |
38 | skipmissing="yes" | |
39 | } | |
ec9315e5 | 40 | |
e12aac5e | 41 | |
c8937ec4 | 42 | [[ $2 ]] && kernel=$2 || kernel=$(uname -r) |
95994c57 | 43 | [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img" |
ec9315e5 | 44 | |
c8937ec4 | 45 | if [[ -f $outfile && ! $force ]]; then |
641cc356 | 46 | echo "Will not override existing initramfs ($outfile) without --force" |
ec9315e5 JK |
47 | exit 1 |
48 | fi | |
49 | ||
49c68fa4 VL |
50 | hookdirs="pre-udev pre-mount pre-pivot mount" |
51 | ||
52 | readonly initdir=$(mktemp -d -t initramfs.XXXXXX) | |
2c6fc388 | 53 | trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die. |
ec9315e5 | 54 | |
49c68fa4 | 55 | export initdir hookdirs dsrc dracutmodules modules |
f4fff04e | 56 | |
0f86847d VL |
57 | # Create some directory structure first |
58 | for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do | |
59 | mkdir -p "$initdir/$d"; | |
60 | done | |
61 | ||
8d02da42 VL |
62 | can_source_module() { |
63 | # $1 = location of module | |
64 | mod=${1##*/}; mod=${mod#[0-9][0-9]}; | |
65 | case $dracutmodules in | |
ba5433e9 PS |
66 | all) [[ $skipmissing ]] || return 0;; |
67 | *) strstr "$dracutmodules " "$mod " || return 1;; | |
8d02da42 | 68 | esac |
ba5433e9 PS |
69 | |
70 | [[ $skipmissing ]] && [[ -x $1/check ]] && { | |
71 | return $("$1/check" >/dev/null 2>&1); | |
72 | } | |
73 | ||
74 | [[ $skipmissing ]] || return 1 | |
75 | return 0 | |
8d02da42 VL |
76 | } |
77 | ||
f04dc5f3 | 78 | # source all our modules |
20abd914 VL |
79 | for moddir in "$dsrc/modules.d"/*; do |
80 | [[ -d $moddir || -L $moddir ]] || continue | |
8d02da42 VL |
81 | can_source_module "$moddir" || continue |
82 | [[ -x $moddir/install ]] && . "$moddir/install" | |
15136762 | 83 | done |
20abd914 | 84 | unset moddir |
aabc0553 | 85 | |
0f86847d | 86 | ## final stuff that has to happen |
bc6b0dec | 87 | |
0f86847d | 88 | # generate module dependencies for the initrd |
3c3e1e0c | 89 | /sbin/depmod -a -b "$initdir" $kernel || { |
3f746592 | 90 | echo "\"/sbin/depmod -a $kernel\" failed." |
641cc356 | 91 | exit 1 |
3c3e1e0c | 92 | } |
ec9315e5 | 93 | |
0f86847d | 94 | # make sure that library links are correct and up to date |
7702658f | 95 | ldconfig -n -r "$initdir" /lib* /usr/lib* |
0f86847d | 96 | |
3c3e1e0c | 97 | ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; ) |