From 43ea36b3e8a00df88de153e81e3668e9ee583391 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 5 Mar 2020 23:28:53 +0800 Subject: [PATCH] Introduce get_kdump_mntpoint_from_target and fix duplicated / User a helper to get the path to mount dump target in kdump kernel, and fix duplicated '/' in the mount path problem. Fixes: bz1785371 Signed-off-by: Kairui Song Acked-by: Dave Young --- kdump-lib.sh | 19 +++++++++++++++++++ kdumpctl | 7 +------ mkdumprd | 20 +++++--------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index b079f27..2157c34 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -258,6 +258,25 @@ get_mntpoint_from_target() findmnt -k -f -n -r -o TARGET --source $1 } +# Get the path where the target will be mounted in kdump kernel +# $1: kdump target device +get_kdump_mntpoint_from_target() +{ + local _mntpoint=$(get_mntpoint_from_target $1) + + # mount under /sysroot if dump to root disk or mount under + # /kdumproot/$_mntpoint in other cases in 2nd kernel. systemd + # will be in charge to umount it. + if [ "$_mntpoint" = "/" ];then + _mntpoint="/sysroot" + else + _mntpoint="/kdumproot/$_mntpoint" + fi + + # strip duplicated "/" + echo $_mntpoint | tr -s "/" +} + # get_option_value # retrieves value of option defined in kdump.conf get_option_value() { diff --git a/kdumpctl b/kdumpctl index fb264c3..081720e 100755 --- a/kdumpctl +++ b/kdumpctl @@ -480,12 +480,7 @@ check_dump_fs_modified() return 2 fi - if [[ "$_target" = "$(get_root_fs_device)" ]]; then - _new_mntpoint="/sysroot" - else - _new_mntpoint="/kdumproot/$(get_mntpoint_from_target $_target)" - fi - + _new_mntpoint="$(get_kdump_mntpoint_from_target $_target)" _dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt) if [[ -z "$_dracut_args" ]];then echo "Warning: No dracut arguments found in initrd" diff --git a/mkdumprd b/mkdumprd index a8f41d4..c80e3e0 100644 --- a/mkdumprd +++ b/mkdumprd @@ -51,21 +51,12 @@ add_dracut_sshkey() { # caller should ensure $1 is valid and mounted in 1st kernel to_mount() { - local _dev=$1 _source _target _fstype _options _mntopts _pdev + local _dev=$1 _source _new_mntpoint _fstype _options _mntopts _pdev _source=$(findmnt -k -f -n -r -o SOURCE $_dev) - _target=$(get_mntpoint_from_target $_dev) - # mount under /sysroot if dump to root disk or mount under - #/kdumproot/$_target in other cases in 2nd kernel. systemd - #will be in charge to umount it. - - if [ "$_target" = "/" ];then - _target="/sysroot" - else - _target="/kdumproot/$_target" - fi - _fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev) + _new_mntpoint=$(get_kdump_mntpoint_from_target $_dev) + [[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS $_dev) if [ -z "$_options" ]; then _options=$(findmnt -k -f -n -r -o OPTIONS $_dev) @@ -87,14 +78,13 @@ to_mount() { # mount it before kdump starts, this is an attempt to improve robustness _options="$_options,nofail,x-systemd.before=initrd-fs.target" - _mntopts="$_target $_fstype $_options" - #for non-nfs _dev converting to use udev persistent name + _mntopts="$_new_mntpoint $_fstype $_options" + # for non-nfs _dev converting to use udev persistent name if [ -b "$_source" ]; then _pdev="$(get_persistent_dev $_source)" if [ -z "$_pdev" ]; then return 1 fi - else _pdev=$_dev fi