]> git.ipfire.org Git - thirdparty/dracut.git/blob - 50-dracut.install
50-dracut.install: install pregenerated initrd
[thirdparty/dracut.git] / 50-dracut.install
1 #!/bin/sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 COMMAND="$1"
6 KERNEL_VERSION="$2"
7 BOOT_DIR_ABS="$3"
8 KERNEL_IMAGE="$4"
9
10 ret=0
11 case "$COMMAND" in
12 add)
13 INITRD_IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/initrd
14 if [[ -f ${INITRD_IMAGE_PREGENERATED} ]]; then
15 # we found an initrd at the same place as the kernel
16 # use this and don't generate a new one
17 cp "$INITRD_IMAGE_PREGENERATED" "$BOOT_DIR_ABS/initrd" \
18 && chown root:root "$BOOT_DIR_ABS/initrd" \
19 && chmod 0600 "$BOOT_DIR_ABS/initrd" \
20 && exit 0
21 fi
22
23 if [[ -f /etc/kernel/cmdline ]]; then
24 readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
25 fi
26
27 if ! [[ "${BOOT_OPTIONS[@]}" ]]; then
28 read -ar BOOT_OPTIONS < /proc/cmdline
29 fi
30
31 unset noimageifnotneeded
32
33 for ((i=0; i < "${#BOOT_OPTIONS[@]}"; i++)); do
34 if [[ ${BOOT_OPTIONS[$i]} == root\=PARTUUID\=* ]]; then
35 noimageifnotneeded="yes"
36 break
37 fi
38 done
39 dracut ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS"/initrd "$KERNEL_VERSION"
40 ret=$?
41 ;;
42 remove)
43 rm -f -- "$BOOT_DIR_ABS"/initrd
44 ret=$?
45 ;;
46 esac
47 exit $ret