119 lines
3.4 KiB
Diff
119 lines
3.4 KiB
Diff
|
From d837ac398492cc2f6683cb8e2cbb80475ba232d5 Mon Sep 17 00:00:00 2001
|
||
|
From: Harald Hoyer <harald@redhat.com>
|
||
|
Date: Sat, 9 Mar 2013 15:09:55 +0100
|
||
|
Subject: [PATCH] add /lib/kernel/install.d/51-dracut-rescue.install
|
||
|
|
||
|
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 | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
|
||
|
Makefile | 1 +
|
||
|
dracut.spec | 1 +
|
||
|
3 files changed, 75 insertions(+)
|
||
|
create mode 100755 51-dracut-rescue.install
|
||
|
|
||
|
diff --git a/51-dracut-rescue.install b/51-dracut-rescue.install
|
||
|
new file mode 100755
|
||
|
index 0000000..844e578
|
||
|
--- /dev/null
|
||
|
+++ b/51-dracut-rescue.install
|
||
|
@@ -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
|
||
|
diff --git a/Makefile b/Makefile
|
||
|
index 7546ac6..a11689c 100644
|
||
|
--- 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
|
||
|
diff --git a/dracut.spec b/dracut.spec
|
||
|
index 707e66a..6d30e57 100644
|
||
|
--- a/dracut.spec
|
||
|
+++ b/dracut.spec
|
||
|
@@ -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
|