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" ;;
21 -h|
--hostonly) hostonly
="-h" ;;
22 --skip-missing) skipmissing
="yes" ;;
28 [[ -f $conffile ]] ||
( [[ -f /etc
/dracut.conf
]] && conffile
="/etc/dracut.conf" )
29 [[ -f $conffile ]] && .
"$conffile"
30 [[ $dracutmodules_l ]] && dracutmodules
=$dracutmodules_l
31 [[ $modules_l ]] && modules
=$modules_l
33 [[ $allowlocal && -f dracut-functions
]] && dsrc
="." || dsrc
=/usr
/lib
/dracut
34 .
$dsrc/dracut-functions
35 dracutfunctions
=$dsrc/dracut-functions
36 export dracutfunctions
38 [[ $dracutmodules ]] || dracutmodules
="auto"
39 [[ $dracutmodules = "auto" ]] && {
43 [[ $dracutmodules = "hostonly" ]] && {
50 [[ $2 ]] && kernel
=$2 || kernel
=$
(uname
-r)
51 [[ $1 ]] && outfile
=$
(readlink
-f $1) || outfile
="/boot/initrd-$kernel.img"
53 if [[ -f $outfile && ! $force ]]; then
54 echo "Will not override existing initramfs ($outfile) without --force"
58 hookdirs
="pre-udev pre-mount pre-pivot mount"
60 readonly initdir
=$
(mktemp
-d -t initramfs.XXXXXX
)
61 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
63 export initdir hookdirs dsrc dracutmodules modules
65 # Create some directory structure first
66 for d
in bin sbin usr
/bin usr
/sbin usr
/lib etc proc sys sysroot dev
/pts
; do
67 mkdir
-p "$initdir/$d";
71 # $1 = location of module
72 [[ $skipmissing ]] ||
return 0
73 [[ -x $1/check
]] ||
return 0
78 # $1 = location of module
79 mod
=${1##*/}; mod
=${mod#[0-9][0-9]};
80 if [[ $dracutmodules != all
]]; then
81 strstr
"$dracutmodules " "$mod " ||
return 1
86 # source all our modules
87 for moddir
in "$dsrc/modules.d"/*; do
88 [[ -d $moddir ||
-L $moddir ]] ||
continue
89 can_source_module
"$moddir" ||
continue
90 [[ -x $moddir/install ]] && .
"$moddir/install"
94 ## final stuff that has to happen
96 # generate module dependencies for the initrd
97 /sbin
/depmod
-a -b "$initdir" $kernel ||
{
98 echo "\"/sbin/depmod -a $kernel\" failed."
102 # make sure that library links are correct and up to date
103 ldconfig
-n -r "$initdir" /lib
* /usr
/lib
*
105 ( cd "$initdir"; find . |
cpio -H newc
-o |
gzip -9 > "$outfile"; )