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