9 error
() { echo "$@" >&2; }
12 [[ $1 = '-n' ]] && cmd
=echo || cmd
=error
14 $cmd "usage: ${0##*/} [--version] [--help] [-v] [-f] [--preload <module>]"
15 $cmd " [--image-version] [--with=<module>]"
16 $cmd " [--nocompress]"
17 $cmd " <initrd-image> <kernel-version>"
19 $cmd " (ex: ${0##*/} /boot/initramfs-$kver.img $kver)"
21 [[ $1 = '-n' ]] && exit 0
25 # Little helper function for reading args from the commandline.
26 # it automatically handles -a b and -a=b variants, and returns 1 if
27 # we need to shift $3.
33 local rematch
='^[^=]*=(.*)$' result
34 if [[ $2 =~
$rematch ]]; then
35 read "$param" <<< "${BASH_REMATCH[1]}"
37 for ((i
=3; $i <= $#; i
++)); do
38 # Only read next arg if it not an arg itself.
39 if [[ ${@:$i:1} = -* ]];then
42 result
="$result ${@:$i:1}"
43 # There is no way to shift our callers args, so
44 # return "no of args" to indicate they should do it instead.
46 read "$1" <<< "$result"
51 # Taken over from SUSE mkinitrd
52 default_kernel_images
() {
53 local regex kernel_image kernel_version version_version initrd_image
54 local qf
='%{NAME}-%{VERSION}-%{RELEASE}\n'
77 if grep -q UML
/proc
/cpuinfo
; then
83 for kernel_image
in $
(ls $boot_dir \
84 |
sed -ne "\|^$regex\(-[0-9.]\+-[0-9]\+-[a-z0-9]\+$\)\?|p" \
85 |
grep -v kdump$
) ; do
87 # Note that we cannot check the RPM database here -- this
88 # script is itself called from within the binary kernel
89 # packages, and rpm does not allow recursive calls.
91 [ -L "$boot_dir/$kernel_image" ] && continue
92 [ "${kernel_image%%.gz}" != "$kernel_image" ] && continue
93 kernel_version
=$
(/usr
/bin
/get_kernel_version \
94 $boot_dir/$kernel_image 2> /dev
/null
)
95 initrd_image
=$
(echo $kernel_image |
sed -e "s|${regex}|initrd|")
96 if [ "$kernel_image" != "$initrd_image" -a \
97 -n "$kernel_version" -a \
98 -d "/lib/modules/$kernel_version" ]; then
99 kernel_images
="$kernel_images $boot_dir/$kernel_image"
100 initrd_images
="$initrd_images $boot_dir/$initrd_image"
103 for kernel_image
in $kernel_images;do
104 kernels
="$kernels ${kernel_image#*-}"
106 for initrd_image
in $initrd_images;do
107 targets
="$targets $initrd_image"
115 --with-usb) read_arg usbmodule
"$@" ||
shift $?
116 basicmodules
="$basicmodules ${usbmodule:-usb-storage}"
118 --with-avail) read_arg modname
"$@" ||
shift $?
119 basicmodules
="$basicmodules $modname";;
120 --with) read_arg modname
"$@" ||
shift $?
121 basicmodules
="$basicmodules $modname";;
123 echo "mkinitrd: dracut compatibility wrapper"
125 -v|
--verbose) dracut_args
="${dracut_args} -v";;
126 -f|
--force) force
=1;;
127 --preload) read_arg modname
"$@" ||
shift $?
128 basicmodules
="$basicmodules $modname";;
129 --image-version) img_vers
=yes;;
130 --rootfs|
-d) read_arg rootfs
"$@" ||
shift $?
131 dracut_args
="${dracut_args} --filesystems $rootfs";;
132 --nocompress) dracut_args
="$dracut_args --no-compress";;
139 --omit-scsi-modules) ;;
140 --omit-ide-modules) ;;
141 --omit-raid-modules) ;;
142 --omit-lvm-modules) ;;
158 --quiet|
-q) quiet
=1;;
159 -b) read_arg boot_dir
"$@" ||
shift $?
160 if [ ! -d $boot_dir ];then
161 error
"Boot directory $boot_dir does not exist"
165 -k) # Would be nice to get a list of images here
166 read_arg kernel_images
"$@" ||
shift $?
167 for kernel_image
in $kernel_images;do
168 kernels
="$kernels ${kernel_image#*-}"
173 -i) read_arg initrd_images
"$@" ||
shift $?
174 for initrd_image
in $initrd_images;do
175 targets
="$targets $boot_dir/$initrd_image"
178 *) if [[ ! $targets ]]; then
180 elif [[ ! $kernels ]]; then
189 [[ $targets && $kernels ]] || default_kernel_images
190 [[ $targets && $kernels ]] ||
(error
"No kernel found in $boot_dir" && usage
)
192 # We can have several targets/kernels, transform the list to an array
194 [[ $kernels ]] && kernels
=( $kernels )
196 [[ $host_only == 1 ]] && dracut_args
="${dracut_args} -H"
197 [[ $force == 1 ]] && dracut_args
="${dracut_args} -f"
199 echo "Creating: target|kernel|dracut args|basicmodules "
200 for ((i
=0 ; $i<${#targets[@]} ; i
++)); do
202 if [[ $img_vers ]];then
203 target
="${targets[$i]}-${kernels[$i]}"
205 target
="${targets[$i]}"
207 kernel
="${kernels[$i]}"
209 # Duplicate code: No way found how to redirect output based on $quiet
210 if [[ $quiet == 1 ]];then
211 echo "$target|$kernel|$dracut_args|$basicmodules"
212 if [[ $basicmodules ]]; then
213 dracut
$dracut_args --add-drivers "$basicmodules" "$target" \
214 "$kernel" &>/dev
/null
216 dracut
$dracut_args "$target" "$kernel" &>/dev
/null
219 if [[ $basicmodules ]]; then
220 dracut
$dracut_args --add-drivers "$basicmodules" "$target" \
223 dracut
$dracut_args "$target" "$kernel"