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.
 
 
 
 
 
 

118 lines
3.1 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
while (($# > 0)); do
case $1 in
-f|--force) force=yes;;
-m|--modules) dracutmodules_l="$2"; shift;;
-d|--drivers) modules_l="$2"; shift;;
-h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
exit 1 ;;
-d|--debug) set -x;;
-v|--verbose) beverbose="yes";;
-c|--conf) conffile="$2"; shift;;
-l|--local) allowlocal="yes" ;;
-h|--hostonly) hostonly="-h" ;;
-i|--include) include_src="$2"; include_target="$3"; shift 2;;
--skip-missing) skipmissing="yes" ;;
*) break ;;
esac
shift
done
[[ -f $conffile ]] || ( [[ -f /etc/dracut.conf ]] && conffile="/etc/dracut.conf" )
[[ -f $conffile ]] && . "$conffile"
[[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l
[[ $modules_l ]] && modules=$modules_l
[[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut
. $dsrc/dracut-functions
dracutfunctions=$dsrc/dracut-functions
export dracutfunctions
[[ $dracutmodules ]] || dracutmodules="auto"
[[ $dracutmodules = "auto" ]] && {
dracutmodules="all"
skipmissing="yes"
}
[[ $dracutmodules = "hostonly" ]] && {
dracutmodules="all"
skipmissing="yes"
hostonly="-h"
}
[[ $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
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
skip_missing() {
# $1 = location of module
[[ $skipmissing ]] || return 0
[[ -x $1/check ]] || return 0
"$1/check" $hostonly
}
can_source_module() {
# $1 = location of module
mod=${1##*/}; mod=${mod#[0-9][0-9]};
if [[ $dracutmodules != all ]]; then
strstr "$dracutmodules " "$mod " || return 1
fi
skip_missing "$1"
}
# source all our modules
for moddir in "$dsrc/modules.d"/*; do
[[ -d $moddir || -L $moddir ]] || continue
can_source_module "$moddir" || continue
[[ -x $moddir/install ]] && . "$moddir/install"
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*
[[ $include_src && $include_target ]] && {
mkdir -p "$initdir$include_target"
cp -a -t "$initdir$include_target" "$include_src"/*
}
[[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n)
( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
[[ "$beverbose" = "yes" ]] && ls -lh "$outfile"
: