[PATCH 47/50] Split out the various things we load into their own modules.

This should make it easier for distros to customize things according to
their preferences.
master
Victor Lowther 2009-02-13 04:43:24 -08:00 committed by Dave Jones
parent bff8c33c2b
commit f4fff04ef1
11 changed files with 56 additions and 70 deletions

55
dracut
View File

@ -8,11 +8,13 @@
# Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
# GPLv2 header here


[ -f /etc/dracut.conf ] && . /etc/dracut.conf

while (($# > 0)); do
case $1 in
-f|--force) force=yes;;
-m|--modules) dracutmodules="$2"; shift;;
-h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
exit 1 ;;
-v|--verbose) set -x;;
@ -22,6 +24,7 @@ while (($# > 0)); do
esac
shift
done
[[ $dracutmodules ]] || dracutmodules="all"

[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
@ -41,61 +44,13 @@ hookdirs="pre-udev pre-mount pre-pivot"
initdir=$(mktemp -d -t initramfs.XXXXXX)
trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.

export initdir hookdirs rulesdir dsrc dracutmodules kmodules

# Create some directory structure first
for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
mkdir -p "$initdir/$d";
done

# executables that we have to have
exe="bash mount mknod mkdir modprobe udevd udevadm nash pidof sleep chroot echo sed"
lvmexe="lvm"
cryptexe="cryptsetup"
# and some things that are nice for debugging
debugexe="ls ln ps grep more dmesg cat"
# udev things we care about
udevexe="/lib/udev/vol_id /lib/udev/console_init"

# install base executables
for binary in $exe $debugexe $udevexe $lvmexe $cryptexe ; do
inst $binary
done

# Prefer dash as /bin/sh if it is available.
if [[ -f /bin/dash ]]; then
inst /bin/dash
ln -sf /bin/dash "${initdir}/bin/sh"
fi

# install our scripts and hooks
inst "$initfile" "/init"
inst "$switchroot" "/sbin/switch_root"
for hookdir in $hookdirs; do
for hook in "$dsrc/$hookdir"/*; do
[[ -f $hook ]] && inst "$hook" "/$hookdir/${hook##*/}"
done
done

# FIXME: hard-coded module list of doom.
[[ $modules ]] || modules="=ata =block =drm dm-crypt aes sha256 cbc"

instmods $modules

# Grab modules for all filesystem types we currently have mounted
while read d mp t rest; do
instmods "$t"
done </proc/mounts

# FIXME: would be nice if we didn't have to know which rules to grab....
# ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies
# of the rules we want so that we just copy those in would be best
mkdir -p "$initdir/lib/udev/rules.d"
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
cp "$rule" "$initdir/lib/udev/rules.d"
done

# terminfo bits make things work better if you fall into interactive mode
for f in $(find /lib/terminfo -type f) ; do cp --parents $f "$initdir" ; done

# source any third-party package provided modules
for f in "$dsrc/modules"/*; do
[[ -x $f ]] && . "$f"

View File

@ -32,6 +32,7 @@ inst_simple() {
local src=$1 target="${initdir}${2:-$1}"
[[ -f $target ]] && return 0
mkdir -p "${target%/*}"
echo "Installing $src" >&2
cp -fL "$src" "$target"
}

@ -132,6 +133,12 @@ inst() {
return 1
}

dracut_install() {
while (($# > 0)); do
inst "$1" && shift
done
}

modcat="/lib/modules/$kernel/modules"
instmods() {
local mod mpargs modpath modname cmd
@ -163,24 +170,4 @@ instmods() {
done
}

findkeymap () {
local MAP=$1
[[ ! -f $MAP ]] && \
MAP=$(find /lib/kbd/keymaps -type f -name $MAP -o -name $MAP.\* | head -n1)
[[ " $KEYMAPS " = *" $MAP "* ]] && return
KEYMAPS="$KEYMAPS $MAP"
case $MAP in
*.gz) cmd=zgrep;;
*.bz2) cmd=bzgrep;;
*) cmd=grep ;;
esac

for INCL in $($cmd "^include " $MAP | cut -d' ' -f2 | tr -d '"'); do
for FN in $(find /lib/kbd/keymaps -type f -name $INCL\*); do
findkeymap $FN
done
done
}


# vim:ts=8:sw=4:sts=4:et

6
modules/00dash Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# Prefer dash as /bin/sh if it is available.
if [[ -f /bin/dash ]]; then
inst /bin/dash
ln -sf /bin/dash "${initdir}/bin/sh"
fi

0
modules/10redhat-i18n Normal file → Executable file
View File

2
modules/90crypt Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
inst cryptsetup

8
modules/90kernel-modules Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# FIXME: hard-coded module list of doom.
instmods ${modules:-=ata =block =drm dm-crypt aes sha256 cbc}

# Grab modules for all filesystem types we currently have mounted
while read d mp t rest; do
instmods "$t"
done </proc/mounts

2
modules/90lvm Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
inst lvm

2
modules/95debug Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
dracut_install ln ps grep more dmesg cat

3
modules/95terminfo Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
# terminfo bits make things work better if you fall into interactive mode
dracut_install $(find /lib/terminfo -type f)

8
modules/95udev-rules Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# FIXME: would be nice if we didn't have to know which rules to grab....
# ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies
# of the rules we want so that we just copy those in would be best
mkdir -p "$initdir/lib/udev/rules.d"
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
inst "$rule" "/lib/udev/rules.d/${rule##*/}"
done

13
modules/99base Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
dracut_install mount mknod mkdir modprobe udevd udevadm pidof sleep \
chroot echo sed sh ls /lib/udev/vol_id /lib/udev/console_init

# install our scripts and hooks
inst "$initfile" "/init"
inst "$switchroot" "/sbin/switch_root"
for hookdir in $hookdirs; do
for hook in "$dsrc/$hookdir"/*; do
[[ -f $hook ]] && inst "$hook" "/$hookdir/${hook##*/}"
done
done