]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
[PATCH 39/50] Prefer /bin/dash as /bin/sh on the initrd if it is available.
[thirdparty/dracut.git] / dracut
CommitLineData
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 13while (($# > 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 24done
ec9315e5 25
c8937ec4 26[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
95994c57 27[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
ec9315e5 28
c8937ec4 29if [[ -f $outfile && ! $force ]]; then
641cc356 30 echo "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
31 exit 1
32fi
33
f9d7779e
VL
34[[ $allowlocal && -f ./init ]] && dsrc="." || dsrc=/usr/libexec/dracut
35. $dsrc/dracut-functions
36initfile=$dsrc/init
37switchroot=$dsrc/switch_root
38rulesdir=$dsrc/rules.d
933a523a 39echoer=$dsrc/echoer
4b3f76db 40hookdirs="pre-udev pre-mount pre-pivot"
5c481d34 41
641cc356 42initdir=$(mktemp -d -t initramfs.XXXXXX)
2c6fc388 43trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
ec9315e5
JK
44
45# executables that we have to have
6dc8676d 46exe="/bin/bash /bin/mount /bin/mknod /bin/mkdir /sbin/modprobe /sbin/udevd /sbin/udevadm /sbin/nash /sbin/pidof /bin/sleep /usr/sbin/chroot /bin/echo /bin/cat /bin/sed"
7a18688c 47lvmexe="/sbin/lvm"
eb25ff7a 48cryptexe="/sbin/cryptsetup"
ec9315e5 49# and some things that are nice for debugging
75ec5873 50debugexe="/bin/ls /bin/ln /bin/ps /bin/grep /bin/more /bin/dmesg"
35c5d61b 51# udev things we care about
aabc0553 52udevexe="/lib/udev/vol_id /lib/udev/console_init"
ec9315e5
JK
53
54# install base files
eb25ff7a 55for binary in $exe $debugexe $udevexe $lvmexe $cryptexe ; do
36b24d7c 56 inst $binary
ec9315e5
JK
57done
58
6dc8676d
VL
59# Prefer dash as /bin/sh if it is available.
60if [[ -f /bin/dash ]]; then
61 inst /bin/dash
62 ln -sf /bin/dash "${initdir}/bin/sh"
63fi
64
35c5d61b 65# FIXME: would be nice if we didn't have to know which rules to grab....
641cc356
JK
66# ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies
67# of the rules we want so that we just copy those in would be best
535df366 68mkdir -p "$initdir/lib/udev/rules.d"
aabc0553 69for 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 70 cp "$rule" "$initdir/lib/udev/rules.d"
35c5d61b
JK
71done
72
ca9f6259 73# terminfo bits make things work better if you fall into interactive mode
641cc356 74for f in $(find /lib/terminfo -type f) ; do cp --parents $f "$initdir" ; done
ca9f6259 75
aabc0553 76# FIXME: i18n stuff isn't really distro-independent :/
3c3e1e0c 77if [[ -f /etc/sysconfig/keyboard || -f /etc/sysconfig/console/default.kmap ]]; then
aabc0553
JK
78 if [ -f /etc/sysconfig/console/default.kmap ]; then
79 KEYMAP=/etc/sysconfig/console/default.kmap
80 else
81 . /etc/sysconfig/keyboard
3c3e1e0c 82 [[ $KEYTABLE && -d /lib/kbd/keymaps ]] && KEYMAP="$KEYTABLE.map"
aabc0553 83 fi
3c3e1e0c 84 if [[ $KEYMAP ]]; then
36b24d7c
VL
85 [ -f /etc/sysconfig/keyboard ] && inst /etc/sysconfig/keyboard
86 inst /bin/loadkeys
aabc0553
JK
87 findkeymap $KEYMAP
88
89 for FN in $KEYMAPS; do
36b24d7c 90 inst $FN
dce3f50a
VL
91 case $FN in
92 *.gz) gzip -d "$initdir$FN" ;;
93 *.bz2) bzip2 -d "$initdir$FN" ;;
aabc0553
JK
94 esac
95 done
96 fi
97fi
98
99if [ -f /etc/sysconfig/i18n ]; then
100 . /etc/sysconfig/i18n
36b24d7c 101 inst /etc/sysconfig/i18n
3c3e1e0c 102 [[ $SYSFONT ]] || SYSFONT=latarcyrheb-sun16
36b24d7c 103 inst /bin/setfont
aabc0553
JK
104
105 for FN in /lib/kbd/consolefonts/$SYSFONT.* ; do
36b24d7c 106 inst "$FN"
e4191d35 107 case $FN in
5a862b96
VL
108 *.gz) gzip -d "$initdir$FN" ;;
109 *.bz2) bzip2 -d "$initdir$FN" ;;
aabc0553
JK
110 esac
111 done
36b24d7c
VL
112 [[ $SYSFONTACM ]] && inst /lib/kbd/consoletrans/$SYSFONTACM
113 [[ $UNIMAP ]] && inst /lib/kbd/unimaps/$UNIMAP
aabc0553
JK
114fi
115
ec9315e5 116# install our files
7f64a3fe
VL
117inst "$initfile" "/init"
118inst "$switchroot" "/sbin/switch_root"
119inst "$echoer" "/echoer"
ec1ad334
VL
120for hookdir in $hookdirs; do
121 for hook in "$dsrc/$hookdir"/*; do
122 [[ -f $hook ]] && inst "$hook" "/$hookdir/${hook##*/}"
123 done
124done
641cc356
JK
125
126# and create some directory structure
e4191d35 127for d in etc proc sys sysroot dev/pts; do mkdir -p "$initdir/$d"; done
641cc356 128# FIXME: hard-coded module list of doom.
3c3e1e0c 129[[ $modules ]] || modules="=ata =block =drm dm-crypt aes sha256 cbc"
641cc356 130
36b24d7c 131instmods $modules
641cc356 132
bc6b0dec
VL
133# Grab modules for all filesystem types we currently know about
134while read d mp t rest; do
135 instmods "$t"
136done </proc/mounts
137
3c3e1e0c 138/sbin/depmod -a -b "$initdir" $kernel || {
641cc356
JK
139 error "\"/sbin/depmod -a $kernel\" failed."
140 exit 1
3c3e1e0c 141}
ec9315e5 142
3c3e1e0c 143( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )