add /lib/kernel/install.d/51-dracut-rescue.install
authorHarald Hoyer <harald@redhat.com>
Sat, 9 Mar 2013 14:09:55 +0000 (15:09 +0100)
committerHarald Hoyer <harald@redhat.com>
Sat, 9 Mar 2013 14:16:31 +0000 (15:16 +0100)
Upon installation of a kernel, check if a rescue image is already
available and if not, create a non-hostonly generic initramfs image with
the rescue module added.

51-dracut-rescue.install [new file with mode: 0755]
Makefile
dracut.spec

diff --git a/51-dracut-rescue.install b/51-dracut-rescue.install
new file mode 100755 (executable)
index 0000000..844e578
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+export LANG=C
+
+COMMAND="$1"
+KERNEL_VERSION="$2"
+BOOT_DIR_ABS="$3"
+BOOT_DIR="${3#/boot}"
+
+[[ -f /etc/os-release ]] && . /etc/os-release
+[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
+if [[ -f /etc/kernel/cmdline ]]; then
+    readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
+fi
+if ! [[ "${BOOT_OPTIONS[@]}" ]]; then
+    readarray -t BOOT_OPTIONS < /proc/cmdline
+fi
+if ! [[ $BOOT_OPTIONS ]]; then
+    exit 1
+fi
+
+LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-00-${KERNEL_VERSION}-rescue.conf"
+
+ret=0
+
+case "$COMMAND" in
+    add)
+        for i in "/boot/loader/entries/${MACHINE_ID}-00-"*"-rescue.conf"; do
+            [[ -f $i ]] && exit 0
+        done
+
+       dracut --no-hostonly  -a "rescue" "$3"/initrd-rescue "$2"
+        ((ret+=$?))
+
+        {
+            echo "title      $PRETTY_NAME - Rescue Image"
+            echo "version    $KERNEL_VERSION"
+            echo "machine-id $MACHINE_ID"
+            echo "options    ${BOOT_OPTIONS[@]} rd.auto=1"
+            echo "linux      $BOOT_DIR/linux"
+            echo "initrd     $BOOT_DIR/initrd-rescue"
+        } > $LOADER_ENTRY
+        ((ret+=$?))
+
+        if (( $ret == 0 )); then
+            command -v yumdb &>/dev/null && \
+                yumdb set installonly keep kernel-$KERNEL_VERSION >/dev/null
+        fi
+
+        ;;
+
+    remove)
+        [[ -f $LOADER_ENTRY ]] || exit 0
+
+        rm -f "$LOADER_ENTRY" "$3"/initrd-rescue
+
+        if command -v yumdb &>/dev/null; then
+            if [[ $(yumdb get installonly kernel-$KERNEL_VERSION 2>/dev/null) == *installonly\ \=\ keep* ]]; then
+                yumdb del installonly kernel-$KERNEL_VERSION >/dev/null
+            fi
+        fi
+        ;;
+
+    *)
+        usage
+        ret=1;;
+esac
+
+((ret+=$?))
+
+exit $ret
index 7546ac6..a11689c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -118,6 +118,7 @@ endif
        fi
        mkdir -p $(DESTDIR)${prefix}/lib/kernel/install.d
        install -m 0755 50-dracut.install $(DESTDIR)${prefix}/lib/kernel/install.d/50-dracut.install
+       install -m 0755 51-dracut-rescue.install $(DESTDIR)${prefix}/lib/kernel/install.d/51-dracut-rescue.install
 
 dracut-version.sh:
        @echo "DRACUT_VERSION=$(VERSION)-$(GITVERSION)" > dracut-version.sh
index 707e66a..6d30e57 100644 (file)
@@ -338,6 +338,7 @@ rm -rf $RPM_BUILD_ROOT
 %endif
 %if 0%{?fedora} || 0%{?rhel} > 6
 %{_prefix}/lib/kernel/install.d/50-dracut.install
+%{_prefix}/lib/kernel/install.d/51-dracut-rescue.install
 %endif
 
 %files network