The /boot directory on some operating systems might be read-only. If we cannot write to $KDUMP_BOOTDIR when generating the kdump initrd, attempt to place the generated initrd at `/var/lib/kdump` instead.
Signed-off by: Kelvin Fan kfan@redhat.com --- 60-kdump.install | 14 ++++++++++---- kdump-lib.sh | 24 +++++++++++++++++------- kdumpctl | 4 ++-- kexec-tools.spec | 2 ++ 4 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/60-kdump.install b/60-kdump.install index 0a3b40e..7221e56 100755 --- a/60-kdump.install +++ b/60-kdump.install @@ -2,17 +2,23 @@
COMMAND="$1" KERNEL_VERSION="$2" -BOOT_DIR_ABS="$3" +KDUMP_INITRD_DIR_ABS="$3" KERNEL_IMAGE="$4"
if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then exit 0 fi
-if [[ -d "$BOOT_DIR_ABS" ]]; then +if [[ -d "$KDUMP_INITRD_DIR_ABS" ]]; then KDUMP_INITRD="initrdkdump" else - BOOT_DIR_ABS="/boot" + # If `KDUMP_BOOTDIR` is not writable, then the kdump + # initrd must have been placed at `/var/lib/kdump` + if [[ ! -w "$KDUMP_BOOTDIR" ]]; then + KDUMP_INITRD_DIR_ABS="/var/lib/kdump" + else + KDUMP_INITRD_DIR_ABS="/boot" + fi KDUMP_INITRD="initramfs-${KERNEL_VERSION}kdump.img" fi
@@ -23,7 +29,7 @@ case "$COMMAND" in # and managed by kdump service ;; remove) - rm -f -- "$BOOT_DIR_ABS/$KDUMP_INITRD" + rm -f -- "$KDUMP_INITRD_DIR_ABS/$KDUMP_INITRD" ret=$? ;; esac diff --git a/kdump-lib.sh b/kdump-lib.sh index 21271cf..5f53a8a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -733,20 +733,30 @@ prepare_kdump_bootinfo() boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" for initrd in $boot_initrdlist; do if [ -f "$KDUMP_BOOTDIR/$initrd" ]; then - DEFAULT_INITRD="$KDUMP_BOOTDIR/$initrd" + defaut_initrd_base="$initrd" + DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base" break fi done
- # Get kdump initrd from default initrd filename + # Create kdump initrd basename from default initrd basename # initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img # initrd => initrdkdump - if [[ -z "$DEFAULT_INITRD" ]]; then - KDUMP_INITRD=${KDUMP_BOOTDIR}/initramfs-${KDUMP_KERNELVER}kdump.img - elif [[ $(basename $DEFAULT_INITRD) == *.* ]]; then - KDUMP_INITRD=${DEFAULT_INITRD%.*}kdump.${DEFAULT_INITRD##*.} + if [[ -z "$defaut_initrd_base" ]]; then + kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img + elif [[ $defaut_initrd_base == *.* ]]; then + kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} else - KDUMP_INITRD=${DEFAULT_INITRD}kdump + kdump_initrd_base=${defaut_initrd_base}kdump + fi + + # Place kdump initrd in `/var/lib/kdump` if `KDUMP_BOOTDIR` not writable + if [[ ! -w "$KDUMP_BOOTDIR" ]];then + var_target_initrd_dir="/var/lib/kdump" + mkdir -p "$var_target_initrd_dir" + KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base" + else + KDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base" fi }
diff --git a/kdumpctl b/kdumpctl index c3311ad..b0846fa 100755 --- a/kdumpctl +++ b/kdumpctl @@ -151,8 +151,8 @@ rebuild_kdump_initrd()
rebuild_initrd() { - if [[ ! -w "$KDUMP_BOOTDIR" ]];then - derror "$KDUMP_BOOTDIR does not have write permission. Can not rebuild $TARGET_INITRD" + if [[ ! -w $(dirname $TARGET_INITRD) ]];then + derror "$(dirname $TARGET_INITRD) does not have write permission. Cannot rebuild $TARGET_INITRD" return 1 fi
diff --git a/kexec-tools.spec b/kexec-tools.spec index 24c6b36..74b7877 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -170,6 +170,7 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_bindir} mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump +mkdir -p -m755 $RPM_BUILD_ROOT%{_sharedstatedir}/kdump install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl
install -m 755 build/sbin/kexec $RPM_BUILD_ROOT/usr/sbin/kexec @@ -335,6 +336,7 @@ done %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d %dir %{_sysconfdir}/kdump/post.d +%dir %{_sharedstatedir}/kdump %{_mandir}/man8/kdumpctl.8.gz %{_mandir}/man8/kexec.8.gz %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64
Hi Kelvin
On Wed, Apr 7, 2021 at 5:51 AM Kelvin Fan kfan@redhat.com wrote:
The /boot directory on some operating systems might be read-only. If we cannot write to $KDUMP_BOOTDIR when generating the kdump initrd, attempt to place the generated initrd at `/var/lib/kdump` instead.
Signed-off by: Kelvin Fan kfan@redhat.com
60-kdump.install | 14 ++++++++++---- kdump-lib.sh | 24 +++++++++++++++++------- kdumpctl | 4 ++-- kexec-tools.spec | 2 ++ 4 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/60-kdump.install b/60-kdump.install index 0a3b40e..7221e56 100755 --- a/60-kdump.install +++ b/60-kdump.install @@ -2,17 +2,23 @@
COMMAND="$1" KERNEL_VERSION="$2" -BOOT_DIR_ABS="$3" +KDUMP_INITRD_DIR_ABS="$3" KERNEL_IMAGE="$4"
if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then exit 0 fi
-if [[ -d "$BOOT_DIR_ABS" ]]; then +if [[ -d "$KDUMP_INITRD_DIR_ABS" ]]; then KDUMP_INITRD="initrdkdump" else
- BOOT_DIR_ABS="/boot"
- # If `KDUMP_BOOTDIR` is not writable, then the kdump
- # initrd must have been placed at `/var/lib/kdump`
- if [[ ! -w "$KDUMP_BOOTDIR" ]]; then
KDUMP_BOOTDIR is an empty value here, I think you can just test [[ -w "/boot" ]] ?
KDUMP_INITRD_DIR_ABS="/var/lib/kdump"
- else
KDUMP_INITRD_DIR_ABS="/boot"
- fi KDUMP_INITRD="initramfs-${KERNEL_VERSION}kdump.img"
fi
@@ -23,7 +29,7 @@ case "$COMMAND" in # and managed by kdump service ;; remove)
rm -f -- "$BOOT_DIR_ABS/$KDUMP_INITRD"
rm -f -- "$KDUMP_INITRD_DIR_ABS/$KDUMP_INITRD" ret=$? ;;
esac diff --git a/kdump-lib.sh b/kdump-lib.sh index 21271cf..5f53a8a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -733,20 +733,30 @@ prepare_kdump_bootinfo() boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" for initrd in $boot_initrdlist; do if [ -f "$KDUMP_BOOTDIR/$initrd" ]; then
DEFAULT_INITRD="$KDUMP_BOOTDIR/$initrd"
defaut_initrd_base="$initrd"
doneDEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base" break fi
- # Get kdump initrd from default initrd filename
- # Create kdump initrd basename from default initrd basename # initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img # initrd => initrdkdump
- if [[ -z "$DEFAULT_INITRD" ]]; then
KDUMP_INITRD=${KDUMP_BOOTDIR}/initramfs-${KDUMP_KERNELVER}kdump.img
- elif [[ $(basename $DEFAULT_INITRD) == *.* ]]; then
KDUMP_INITRD=${DEFAULT_INITRD%.*}kdump.${DEFAULT_INITRD##*.}
- if [[ -z "$defaut_initrd_base" ]]; then
kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img
- elif [[ $defaut_initrd_base == *.* ]]; then
elsekdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.}
KDUMP_INITRD=${DEFAULT_INITRD}kdump
kdump_initrd_base=${defaut_initrd_base}kdump
- fi
- # Place kdump initrd in `/var/lib/kdump` if `KDUMP_BOOTDIR` not writable
- if [[ ! -w "$KDUMP_BOOTDIR" ]];then
var_target_initrd_dir="/var/lib/kdump"
mkdir -p "$var_target_initrd_dir"
KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base"
- else
fiKDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base"
}
diff --git a/kdumpctl b/kdumpctl index c3311ad..b0846fa 100755 --- a/kdumpctl +++ b/kdumpctl @@ -151,8 +151,8 @@ rebuild_kdump_initrd()
rebuild_initrd() {
if [[ ! -w "$KDUMP_BOOTDIR" ]];then
derror "$KDUMP_BOOTDIR does not have write permission. Can not rebuild $TARGET_INITRD"
if [[ ! -w $(dirname $TARGET_INITRD) ]];then
derror "$(dirname $TARGET_INITRD) does not have write permission. Cannot rebuild $TARGET_INITRD" return 1 fi
diff --git a/kexec-tools.spec b/kexec-tools.spec index 24c6b36..74b7877 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -170,6 +170,7 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_bindir} mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump +mkdir -p -m755 $RPM_BUILD_ROOT%{_sharedstatedir}/kdump install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl
install -m 755 build/sbin/kexec $RPM_BUILD_ROOT/usr/sbin/kexec @@ -335,6 +336,7 @@ done %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d %dir %{_sysconfdir}/kdump/post.d +%dir %{_sharedstatedir}/kdump %{_mandir}/man8/kdumpctl.8.gz %{_mandir}/man8/kexec.8.gz %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 -- 2.29.2 _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Everything else looks good to me now !