]>
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 | |
641cc356 JK |
11 | [ -f /etc/dracut.conf ] && . /etc/dracut.conf |
12 | ||
b368a5f3 | 13 | while (($# > 0)); do |
641cc356 | 14 | case $1 in |
b368a5f3 VL |
15 | -f|--force) force=yes;; |
16 | -h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>" | |
17 | exit 1 ;; | |
18 | -v|--verbose) set -x;; | |
19 | -l|--local) allowlocal="yes" ;; | |
20 | --allow-missing) : ;; | |
21 | *) break ;; | |
641cc356 | 22 | esac |
b368a5f3 | 23 | shift |
641cc356 | 24 | done |
ec9315e5 | 25 | |
c8937ec4 VL |
26 | [[ $2 ]] && kernel=$2 || kernel=$(uname -r) |
27 | [[ $1 ]] && outfile=$(readlink -f $1) || \ | |
641cc356 | 28 | outfile="/boot/initrd-$kernel.img" |
ec9315e5 | 29 | |
c8937ec4 | 30 | if [[ -f $outfile && ! $force ]]; then |
641cc356 | 31 | echo "Will not override existing initramfs ($outfile) without --force" |
ec9315e5 JK |
32 | exit 1 |
33 | fi | |
34 | ||
f9d7779e VL |
35 | [[ $allowlocal && -f ./init ]] && dsrc="." || dsrc=/usr/libexec/dracut |
36 | . $dsrc/dracut-functions | |
37 | initfile=$dsrc/init | |
38 | switchroot=$dsrc/switch_root | |
39 | rulesdir=$dsrc/rules.d | |
5c481d34 | 40 | |
641cc356 | 41 | initdir=$(mktemp -d -t initramfs.XXXXXX) |
ec9315e5 JK |
42 | |
43 | # executables that we have to have | |
70c26b7f | 44 | exe="/bin/bash /bin/mount /bin/mknod /bin/mkdir /sbin/modprobe /sbin/udevd /sbin/udevadm /sbin/nash /sbin/pidof /bin/sleep /usr/sbin/chroot" |
7a18688c | 45 | lvmexe="/sbin/lvm" |
eb25ff7a | 46 | cryptexe="/sbin/cryptsetup" |
ec9315e5 | 47 | # and some things that are nice for debugging |
641cc356 | 48 | debugexe="/bin/ls /bin/cat /bin/ln /bin/ps /bin/grep /bin/more" |
35c5d61b | 49 | # udev things we care about |
aabc0553 | 50 | udevexe="/lib/udev/vol_id /lib/udev/console_init" |
ec9315e5 JK |
51 | |
52 | # install base files | |
eb25ff7a | 53 | for binary in $exe $debugexe $udevexe $lvmexe $cryptexe ; do |
e4191d35 | 54 | inst $binary "$initdir" |
ec9315e5 JK |
55 | done |
56 | ||
35c5d61b | 57 | # FIXME: would be nice if we didn't have to know which rules to grab.... |
641cc356 JK |
58 | # ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies |
59 | # of the rules we want so that we just copy those in would be best | |
535df366 | 60 | mkdir -p "$initdir/lib/udev/rules.d" |
aabc0553 | 61 | for rule in /lib/udev/rules.d/10-console* /lib/udev/rules.d/40-redhat* /lib/udev/rules.d/50* /lib/udev/rules.d/60-persistent-storage.rules /lib/udev/rules.d/61*edd* /lib/udev/rules.d/64* /lib/udev/rules.d/80* /lib/udev/rules.d/95* $rulesdir/*.rules ; do |
e4191d35 | 62 | cp "$rule" "$initdir/lib/udev/rules.d" |
35c5d61b JK |
63 | done |
64 | ||
ca9f6259 | 65 | # terminfo bits make things work better if you fall into interactive mode |
641cc356 | 66 | for f in $(find /lib/terminfo -type f) ; do cp --parents $f "$initdir" ; done |
ca9f6259 | 67 | |
aabc0553 JK |
68 | # FIXME: i18n stuff isn't really distro-independent :/ |
69 | if [ -f /etc/sysconfig/keyboard ] || [ -f /etc/sysconfig/console/default.kmap ]; then | |
70 | if [ -f /etc/sysconfig/console/default.kmap ]; then | |
71 | KEYMAP=/etc/sysconfig/console/default.kmap | |
72 | else | |
73 | . /etc/sysconfig/keyboard | |
74 | if [ -n "$KEYTABLE" -a -d "/lib/kbd/keymaps" ]; then | |
75 | KEYMAP="$KEYTABLE.map" | |
76 | fi | |
77 | fi | |
78 | if [ -n "$KEYMAP" ]; then | |
79 | [ -f /etc/sysconfig/keyboard ] && inst /etc/sysconfig/keyboard "$initdir" | |
80 | inst /bin/loadkeys "$initdir" | |
81 | findkeymap $KEYMAP | |
82 | ||
83 | for FN in $KEYMAPS; do | |
84 | inst $FN "$initdir" | |
85 | case "$FN" in | |
86 | *.gz) | |
87 | gzip -d "$initdir$FN" | |
88 | ;; | |
89 | *.bz2) | |
90 | bzip2 -d "$initdir$FN" | |
91 | ;; | |
92 | esac | |
93 | done | |
94 | fi | |
95 | fi | |
96 | ||
97 | if [ -f /etc/sysconfig/i18n ]; then | |
98 | . /etc/sysconfig/i18n | |
99 | inst /etc/sysconfig/i18n "$initdir" | |
100 | [ -z "$SYSFONT" ] && SYSFONT=latarcyrheb-sun16 | |
101 | inst /bin/setfont "$initdir" | |
102 | ||
103 | for FN in /lib/kbd/consolefonts/$SYSFONT.* ; do | |
e4191d35 VL |
104 | inst "$FN" "$initdir" |
105 | case $FN in | |
aabc0553 JK |
106 | *.gz) |
107 | gzip -d "$MNTIMAGE$FN" | |
108 | ;; | |
109 | *.bz2) | |
110 | bzip2 -d "$MNTIMAGE$FN" | |
111 | ;; | |
112 | esac | |
113 | done | |
114 | if [ -n "$SYSFONTACM" ]; then | |
115 | inst /lib/kbd/consoletrans/$SYSFONTACM "$initdir" | |
116 | fi | |
117 | if [ -n "$UNIMAP" ]; then | |
118 | inst /lib/kbd/unimaps/$UNIMAP "$initdir" | |
119 | fi | |
120 | fi | |
121 | ||
ec9315e5 | 122 | # install our files |
e4191d35 VL |
123 | cp $initfile "$initdir/init" |
124 | cp $switchroot "$initdir/sbin/switch_root" | |
641cc356 JK |
125 | |
126 | # and create some directory structure | |
e4191d35 | 127 | for d in etc proc sys sysroot dev/pts; do mkdir -p "$initdir/$d"; done |
641cc356 | 128 | # FIXME: hard-coded module list of doom. |
549e53a4 | 129 | [ -z "$modules" ] && modules="=ata =block =drm dm-crypt aes sha256 cbc" |
641cc356 | 130 | |
e4191d35 | 131 | mkdir -p "$initdir/lib/modules/$kernel" |
641cc356 JK |
132 | # expand out module deps, etc |
133 | for mod in $(resolveAndExpandModules $modules) ; do | |
e4191d35 | 134 | installmodule $mod "$initdir" |
641cc356 JK |
135 | done |
136 | ||
e4191d35 | 137 | /sbin/depmod -a -b "$initdir" $kernel |
641cc356 JK |
138 | if [ $? -ne 0 ]; then |
139 | error "\"/sbin/depmod -a $kernel\" failed." | |
140 | exit 1 | |
f39a1046 | 141 | fi |
ec9315e5 | 142 | |
0c70846e JK |
143 | # plymouth |
144 | if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then | |
641cc356 | 145 | /usr/libexec/plymouth/plymouth-populate-initrd -t "$initdir" || : |
0c70846e JK |
146 | fi |
147 | ||
e4191d35 VL |
148 | pushd "$initdir" >/dev/null |
149 | find . |cpio -H newc -o |gzip -9 > "$outfile" | |
ec9315e5 | 150 | popd >/dev/null |