Blame 0002-add-lib-kernel-install.d-51-dracut-rescue.install.patch

Harald Hoyer 52ce14
From d837ac398492cc2f6683cb8e2cbb80475ba232d5 Mon Sep 17 00:00:00 2001
Harald Hoyer 52ce14
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 52ce14
Date: Sat, 9 Mar 2013 15:09:55 +0100
Harald Hoyer 52ce14
Subject: [PATCH] add /lib/kernel/install.d/51-dracut-rescue.install
Harald Hoyer 52ce14
Harald Hoyer 52ce14
Upon installation of a kernel, check if a rescue image is already
Harald Hoyer 52ce14
available and if not, create a non-hostonly generic initramfs image with
Harald Hoyer 52ce14
the rescue module added.
Harald Hoyer 52ce14
---
Harald Hoyer 52ce14
 51-dracut-rescue.install | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
Harald Hoyer 52ce14
 Makefile                 |  1 +
Harald Hoyer 52ce14
 dracut.spec              |  1 +
Harald Hoyer 52ce14
 3 files changed, 75 insertions(+)
Harald Hoyer 52ce14
 create mode 100755 51-dracut-rescue.install
Harald Hoyer 52ce14
Harald Hoyer 52ce14
diff --git a/51-dracut-rescue.install b/51-dracut-rescue.install
Harald Hoyer 52ce14
new file mode 100755
Harald Hoyer 52ce14
index 0000000..844e578
Harald Hoyer 52ce14
--- /dev/null
Harald Hoyer 52ce14
+++ b/51-dracut-rescue.install
Harald Hoyer 52ce14
@@ -0,0 +1,73 @@
Harald Hoyer 52ce14
+#!/bin/sh
Harald Hoyer 52ce14
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer 52ce14
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+export LANG=C
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+COMMAND="$1"
Harald Hoyer 52ce14
+KERNEL_VERSION="$2"
Harald Hoyer 52ce14
+BOOT_DIR_ABS="$3"
Harald Hoyer 52ce14
+BOOT_DIR="${3#/boot}"
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+[[ -f /etc/os-release ]] && . /etc/os-release
Harald Hoyer 52ce14
+[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
Harald Hoyer 52ce14
+if [[ -f /etc/kernel/cmdline ]]; then
Harald Hoyer 52ce14
+    readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
Harald Hoyer 52ce14
+fi
Harald Hoyer 52ce14
+if ! [[ "${BOOT_OPTIONS[@]}" ]]; then
Harald Hoyer 52ce14
+    readarray -t BOOT_OPTIONS < /proc/cmdline
Harald Hoyer 52ce14
+fi
Harald Hoyer 52ce14
+if ! [[ $BOOT_OPTIONS ]]; then
Harald Hoyer 52ce14
+    exit 1
Harald Hoyer 52ce14
+fi
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-00-${KERNEL_VERSION}-rescue.conf"
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+ret=0
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+case "$COMMAND" in
Harald Hoyer 52ce14
+    add)
Harald Hoyer 52ce14
+        for i in "/boot/loader/entries/${MACHINE_ID}-00-"*"-rescue.conf"; do
Harald Hoyer 52ce14
+            [[ -f $i ]] && exit 0
Harald Hoyer 52ce14
+        done
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+	dracut --no-hostonly  -a "rescue" "$3"/initrd-rescue "$2"
Harald Hoyer 52ce14
+        ((ret+=$?))
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        {
Harald Hoyer 52ce14
+            echo "title      $PRETTY_NAME - Rescue Image"
Harald Hoyer 52ce14
+            echo "version    $KERNEL_VERSION"
Harald Hoyer 52ce14
+            echo "machine-id $MACHINE_ID"
Harald Hoyer 52ce14
+            echo "options    ${BOOT_OPTIONS[@]} rd.auto=1"
Harald Hoyer 52ce14
+            echo "linux      $BOOT_DIR/linux"
Harald Hoyer 52ce14
+            echo "initrd     $BOOT_DIR/initrd-rescue"
Harald Hoyer 52ce14
+        } > $LOADER_ENTRY
Harald Hoyer 52ce14
+        ((ret+=$?))
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        if (( $ret == 0 )); then
Harald Hoyer 52ce14
+            command -v yumdb &>/dev/null && \
Harald Hoyer 52ce14
+                yumdb set installonly keep kernel-$KERNEL_VERSION >/dev/null
Harald Hoyer 52ce14
+        fi
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        ;;
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+    remove)
Harald Hoyer 52ce14
+        [[ -f $LOADER_ENTRY ]] || exit 0
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        rm -f "$LOADER_ENTRY" "$3"/initrd-rescue
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        if command -v yumdb &>/dev/null; then
Harald Hoyer 52ce14
+            if [[ $(yumdb get installonly kernel-$KERNEL_VERSION 2>/dev/null) == *installonly\ \=\ keep* ]]; then
Harald Hoyer 52ce14
+                yumdb del installonly kernel-$KERNEL_VERSION >/dev/null
Harald Hoyer 52ce14
+            fi
Harald Hoyer 52ce14
+        fi
Harald Hoyer 52ce14
+        ;;
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+    *)
Harald Hoyer 52ce14
+        usage
Harald Hoyer 52ce14
+        ret=1;;
Harald Hoyer 52ce14
+esac
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+((ret+=$?))
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+exit $ret
Harald Hoyer 52ce14
diff --git a/Makefile b/Makefile
Harald Hoyer 52ce14
index 7546ac6..a11689c 100644
Harald Hoyer 52ce14
--- a/Makefile
Harald Hoyer 52ce14
+++ b/Makefile
Harald Hoyer 52ce14
@@ -118,6 +118,7 @@ endif
Harald Hoyer 52ce14
 	fi
Harald Hoyer 52ce14
 	mkdir -p $(DESTDIR)${prefix}/lib/kernel/install.d
Harald Hoyer 52ce14
 	install -m 0755 50-dracut.install $(DESTDIR)${prefix}/lib/kernel/install.d/50-dracut.install
Harald Hoyer 52ce14
+	install -m 0755 51-dracut-rescue.install $(DESTDIR)${prefix}/lib/kernel/install.d/51-dracut-rescue.install
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 dracut-version.sh:
Harald Hoyer 52ce14
 	@echo "DRACUT_VERSION=$(VERSION)-$(GITVERSION)" > dracut-version.sh
Harald Hoyer 52ce14
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer 52ce14
index 707e66a..6d30e57 100644
Harald Hoyer 52ce14
--- a/dracut.spec
Harald Hoyer 52ce14
+++ b/dracut.spec
Harald Hoyer 52ce14
@@ -338,6 +338,7 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer 52ce14
 %endif
Harald Hoyer 52ce14
 %if 0%{?fedora} || 0%{?rhel} > 6
Harald Hoyer 52ce14
 %{_prefix}/lib/kernel/install.d/50-dracut.install
Harald Hoyer 52ce14
+%{_prefix}/lib/kernel/install.d/51-dracut-rescue.install
Harald Hoyer 52ce14
 %endif
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 %files network