2008-12-18 23:59:55 +03:00
#!/bin/bash
2008-12-18 01:51:15 +03:00
#
# Generator script for a dracut initramfs
# Tries to retain some degree of compatibility with the command line
# of the various mkinitrd implementations out there
#
2009-02-13 15:41:50 +03:00
2008-12-18 01:51:15 +03:00
# Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
# GPLv2 header here
2008-12-11 00:32:21 +03:00
2009-02-13 15:43:24 +03:00
2008-12-18 01:51:15 +03:00
[ -f /etc/dracut.conf ] && . /etc/dracut.conf
2009-02-13 15:41:52 +03:00
while (($# > 0)); do
2008-12-18 01:51:15 +03:00
case $1 in
2009-02-13 15:41:52 +03:00
-f|--force) force=yes;;
2009-02-13 15:43:24 +03:00
-m|--modules) dracutmodules="$2"; shift;;
2009-02-13 15:41:52 +03:00
-h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
exit 1 ;;
-v|--verbose) set -x;;
-l|--local) allowlocal="yes" ;;
--allow-missing) : ;;
*) break ;;
2008-12-18 01:51:15 +03:00
esac
2009-02-13 15:41:52 +03:00
shift
2008-12-18 01:51:15 +03:00
done
2009-02-13 15:43:24 +03:00
[[ $dracutmodules ]] || dracutmodules="all"
2008-12-11 00:32:21 +03:00
2009-02-13 15:41:54 +03:00
[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
2009-02-13 15:42:13 +03:00
[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
2008-12-11 00:32:21 +03:00
2009-02-13 15:41:54 +03:00
if [[ -f $outfile && ! $force ]]; then
2008-12-18 01:51:15 +03:00
echo "Will not override existing initramfs ($outfile) without --force"
2008-12-11 00:32:21 +03:00
exit 1
fi
2009-02-13 15:41:59 +03:00
[[ $allowlocal && -f ./init ]] && dsrc="." || dsrc=/usr/libexec/dracut
. $dsrc/dracut-functions
initfile=$dsrc/init
switchroot=$dsrc/switch_root
rulesdir=$dsrc/rules.d
2009-02-13 15:42:52 +03:00
hookdirs="pre-udev pre-mount pre-pivot"
2008-12-18 23:57:47 +03:00
2008-12-18 01:51:15 +03:00
initdir=$(mktemp -d -t initramfs.XXXXXX)
2009-02-13 15:42:36 +03:00
trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
2008-12-11 00:32:21 +03:00
2009-02-20 20:24:18 +03:00
export initdir hookdirs rulesdir dsrc dracutmodules modules
2009-02-13 15:43:24 +03:00
2009-02-13 15:43:07 +03:00
# 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
2009-02-13 15:43:26 +03:00
# source all our modules
2009-02-20 20:24:18 +03:00
for f in "$dsrc/modules"/*.sh; do
mod=${f##*/}; mod=${mod#[0-9][0-9]}; mod=${mod%.sh}
2009-02-13 15:43:26 +03:00
if [[ $dracutmodules = all ]] || strstr "$dracutmodules" "$mod"; then
[[ -x $f ]] && . "$f"
fi
2009-02-13 15:43:12 +03:00
done
2009-01-05 22:40:34 +03:00
2009-02-13 15:43:07 +03:00
## final stuff that has to happen
2009-02-13 15:42:33 +03:00
2009-02-13 15:43:07 +03:00
# generate module dependencies for the initrd
2009-02-13 15:42:04 +03:00
/sbin/depmod -a -b "$initdir" $kernel || {
2008-12-18 01:51:15 +03:00
error "\"/sbin/depmod -a $kernel\" failed."
exit 1
2009-02-13 15:42:04 +03:00
}
2008-12-11 00:32:21 +03:00
2009-02-13 15:43:07 +03:00
# make sure that library links are correct and up to date
ldconfig -r "$initdir"
2009-02-13 15:42:04 +03:00
( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )