]>
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 VL |
20 | -l|--local) allowlocal="yes" ;; |
21 | --allow-missing) : ;; | |
22 | *) break ;; | |
641cc356 | 23 | esac |
b368a5f3 | 24 | shift |
641cc356 | 25 | done |
4cba351e PS |
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 | |
9a8a00cf VL |
32 | |
33 | [[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut | |
34 | . $dsrc/dracut-functions | |
35 | ||
f4fff04e | 36 | [[ $dracutmodules ]] || dracutmodules="all" |
ec9315e5 | 37 | |
c8937ec4 | 38 | [[ $2 ]] && kernel=$2 || kernel=$(uname -r) |
95994c57 | 39 | [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img" |
ec9315e5 | 40 | |
c8937ec4 | 41 | if [[ -f $outfile && ! $force ]]; then |
641cc356 | 42 | echo "Will not override existing initramfs ($outfile) without --force" |
ec9315e5 JK |
43 | exit 1 |
44 | fi | |
45 | ||
49c68fa4 VL |
46 | hookdirs="pre-udev pre-mount pre-pivot mount" |
47 | ||
48 | readonly initdir=$(mktemp -d -t initramfs.XXXXXX) | |
2c6fc388 | 49 | trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die. |
ec9315e5 | 50 | |
49c68fa4 | 51 | export initdir hookdirs dsrc dracutmodules modules |
f4fff04e | 52 | |
0f86847d VL |
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 | ||
8d02da42 VL |
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 | ||
f04dc5f3 | 70 | # source all our modules |
20abd914 VL |
71 | for moddir in "$dsrc/modules.d"/*; do |
72 | [[ -d $moddir || -L $moddir ]] || continue | |
8d02da42 VL |
73 | can_source_module "$moddir" || continue |
74 | [[ -x $moddir/install ]] && . "$moddir/install" | |
15136762 | 75 | done |
20abd914 | 76 | unset moddir |
aabc0553 | 77 | |
0f86847d | 78 | ## final stuff that has to happen |
bc6b0dec | 79 | |
0f86847d | 80 | # generate module dependencies for the initrd |
3c3e1e0c | 81 | /sbin/depmod -a -b "$initdir" $kernel || { |
3f746592 | 82 | echo "\"/sbin/depmod -a $kernel\" failed." |
641cc356 | 83 | exit 1 |
3c3e1e0c | 84 | } |
ec9315e5 | 85 | |
0f86847d | 86 | # make sure that library links are correct and up to date |
7702658f | 87 | ldconfig -n -r "$initdir" /lib* /usr/lib* |
0f86847d | 88 | |
3c3e1e0c | 89 | ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; ) |