You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
2.2 KiB

#!/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
for i in "$@"; do
case $i in
-l|--local) allowlocal="yes" ;;
esac
done
if [[ $allowlocal && -f dracut.conf ]]; then
. dracut.conf
else
[ -f /etc/dracut.conf ] && . /etc/dracut.conf
fi
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 dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut
. $dsrc/dracut-functions
hookdirs="pre-udev pre-mount pre-pivot mount"
readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
export initdir hookdirs 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 moddir in "$dsrc/modules.d"/*; do
[[ -d $moddir || -L $moddir ]] || continue
mod=${moddir##*/}; mod=${mod#[0-9][0-9]};
if [[ $dracutmodules = all ]] || strstr "$dracutmodules" "$mod"; then
[[ -x $moddir/install ]] && . "$moddir/install"
fi
done
unset moddir
## final stuff that has to happen
# generate module dependencies for the initrd
/sbin/depmod -a -b "$initdir" $kernel || {
echo "\"/sbin/depmod -a $kernel\" failed."
exit 1
}
# make sure that library links are correct and up to date
ldconfig -n -r "$initdir" /lib* /usr/lib*
( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )