dracut/dracut

74 lines
2.0 KiB
Plaintext
Raw Normal View History

2008-12-18 23:59:55 +03:00
#!/bin/bash
#
# Generator script for a dracut initramfs
# Tries to retain some degree of compatibility with the command line
# of the various mkinitrd implementations out there
#
# 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;;
-l|--local) allowlocal="yes" ;;
--allow-missing) : ;;
*) break ;;
esac
shift
done
[[ $dracutmodules ]] || dracutmodules="all"
[[ $2 ]] && kernel=$2 || kernel=$(uname -r)
[[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
if [[ -f $outfile && ! $force ]]; then
echo "Will not override existing initramfs ($outfile) without --force"
exit 1
fi
[[ $allowlocal && -f ./init ]] && dsrc="." || dsrc=/usr/libexec/dracut
. $dsrc/dracut-functions
initfile=$dsrc/init
switchroot=$dsrc/switch_root
rulesdir=$dsrc/rules.d
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 modules
# 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
# source all our modules
for f in "$dsrc/modules"/*.sh; do
mod=${f##*/}; mod=${mod#[0-9][0-9]}; mod=${mod%.sh}
if [[ $dracutmodules = all ]] || strstr "$dracutmodules" "$mod"; then
[[ -x $f ]] && . "$f"
fi
done
## final stuff that has to happen
# generate module dependencies for the initrd
/sbin/depmod -a -b "$initdir" $kernel || {
error "\"/sbin/depmod -a $kernel\" failed."
exit 1
}
# make sure that library links are correct and up to date
ldconfig -r "$initdir"
( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )