]> git.ipfire.org Git - thirdparty/dracut.git/blob - 50-dracut.install
iscsi: always popd, even if there is no iscsi device
[thirdparty/dracut.git] / 50-dracut.install
1 #!/bin/bash
2
3 COMMAND="$1"
4 KERNEL_VERSION="$2"
5 BOOT_DIR_ABS="$3"
6 KERNEL_IMAGE="$4"
7
8 # If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory.
9 # So, let's skip to create initrd.
10 if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
11 exit 0
12 fi
13
14 if [[ -d "$BOOT_DIR_ABS" ]]; then
15 INITRD="initrd"
16 else
17 BOOT_DIR_ABS="/boot"
18 INITRD="initramfs-${KERNEL_VERSION}.img"
19 fi
20
21 ret=0
22 case "$COMMAND" in
23 add)
24 INITRD_IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/initrd
25 if [[ -f ${INITRD_IMAGE_PREGENERATED} ]]; then
26 # we found an initrd at the same place as the kernel
27 # use this and don't generate a new one
28 cp --reflink=auto "$INITRD_IMAGE_PREGENERATED" "$BOOT_DIR_ABS/$INITRD" \
29 && chown root:root "$BOOT_DIR_ABS/$INITRD" \
30 && chmod 0600 "$BOOT_DIR_ABS/$INITRD" \
31 && exit 0
32 fi
33
34 if [[ -f /etc/kernel/cmdline ]]; then
35 read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
36 elif [[ -f /usr/lib/kernel/cmdline ]]; then
37 read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline
38 fi
39
40 if ! [[ ${BOOT_OPTIONS[*]} ]]; then
41 read -r -d '' -a BOOT_OPTIONS < /proc/cmdline
42 fi
43
44 unset noimageifnotneeded
45
46 for ((i=0; i < "${#BOOT_OPTIONS[@]}"; i++)); do
47 if [[ ${BOOT_OPTIONS[$i]} == root\=PARTUUID\=* ]]; then
48 noimageifnotneeded="yes"
49 break
50 fi
51 done
52 dracut -f ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
53 ret=$?
54 ;;
55 remove)
56 rm -f -- "$BOOT_DIR_ABS/$INITRD"
57 ret=$?
58 ;;
59 esac
60 exit $ret