3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
8 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
13 -f|
--force) force
=yes;;
14 -m|
--modules) dracutmodules_l
="$2"; shift;;
15 -d|
--drivers) modules_l
="$2"; shift;;
16 -h|
--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
18 -v|
--verbose) set -x;;
19 -c|
--conf) conffile
="$2"; shift;;
20 -l|
--local) allowlocal
="yes" ;;
27 [[ -f $conffile ]] ||
[[ -f /etc
/dracut.conf
]] && conffile
="/etc/dracut.conf"
28 [[ -f $conffile ]] && .
"$conffile"
30 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodule_l
31 [[ $modules_l ]] && modules
=$modules_l
33 [[ $allowlocal && -f dracut-functions
]] && dsrc
="." || dsrc
=/usr
/lib
/dracut
34 .
$dsrc/dracut-functions
36 [[ $dracutmodules ]] || dracutmodules
="all"
38 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
39 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
41 if [[ -f $outfile && ! $force ]]; then
42 echo "Will not override existing initramfs ($outfile) without --force"
46 hookdirs
="pre-udev pre-mount pre-pivot mount"
48 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
49 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
51 export initdir hookdirs dsrc dracutmodules modules
53 # Create some directory structure first
54 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot dev
/pts
; do
55 mkdir
-p "$initdir/$d";
59 # $1 = location of module
60 mod
=${1##*/}; mod
=${mod#[0-9][0-9]};
61 case $dracutmodules in
63 auto
) [[ -x $1/check
]] ||
return 0
64 "$1/check" >/dev
/null
2>&1 && return 0 ;;
65 *) strstr
"$dracutmodules" "$mod" && return 0;;
70 # source all our modules
71 for moddir
in "$dsrc/modules.d"/*; do
72 [[ -d $moddir ||
-L $moddir ]] ||
continue
73 can_source_module
"$moddir" ||
continue
74 [[ -x $moddir/install ]] && .
"$moddir/install"
78 ## final stuff that has to happen
80 # generate module dependencies for the initrd
81 /sbin
/depmod
-a -b "$initdir" $kernel ||
{
82 echo "\"/sbin/depmod -a $kernel\" failed."
86 # make sure that library links are correct and up to date
87 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
89 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )