On 2016/04/20 at 18:07, Pratyush Anand wrote:
kdump also passes persistent device mapping as --mount or --device
argument
of dracut. However this persistent id (UUID) is changed if dump target is
re-formated.
kdumpctl must have a mechanism to recognise this modification, so that its
service restart is able to rebuild initramfs.
Testing:
a) Attach an IDE device, lets say it is /dev/sdb1
b) Format it as ext4
# mkfs.ext4 /dev/sdb1
# blkid /dev/sdb1
/dev/sdb1: UUID="21c7baff-e35d-49c7-aa08-0fba4513f5bf" TYPE="ext4"
c) Mount it into /mnt and create a var/crash directory in it.
# mount /dev/sdb1 /mnt;mkdir /mnt/var;mkdir /mnt/var/crash
d) Add following line in /etc/kdump.conf
ext4 /dev/sdb1
e) Restart kdumpctl
# kdumpctl restart
f) crash
# echo c > /proc/sysrq-trigger
g) Here you will be able save vmcore with or without this patch.
h) repeat step (b), (c), (e) and (f)
i) Now you will be able to save vmcore only when you have this patch in
your kexec-tools. Your initramfs will be rebuilt when you repeat step (e)
after reformatting.
Signed-off-by: Pratyush Anand <panand(a)redhat.com>
---
kdumpctl | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/kdumpctl b/kdumpctl
index 1cba00b9dc0f..f7e3af8733f5 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -359,6 +359,39 @@ is_files_modified()
return 0
}
+is_fs_uuid_changed()
+{
+ local _target _dracut_args _uuid
+
+ _target=$(egrep "^ext[234]|^xfs|^btrfs" /etc/kdump.conf)
+
+ #if dump target does not exist then do not rebuild
+ [[ -n "$_target" ]] || return 0
+
+ _dracut_args=$(lsinitrd $TARGET_INITRD | grep "^Arguments:" | head -1)
+ if [[ -z "$_dracut_args" ]];then
+ echo "Warning: No dracut arguments found in initrd"
+ return 0
+ fi
+ #if --mount or --device is not by UUID, then also do not rebuild
+ echo $_dracut_args | grep "by-uuid" &> /dev/null
+ [[ $? -eq 0 ]] || return 0
May be "[[ $? -ne 0 ]] && return 0" is more readable, but that's ok
:-)
Additionally, for device mappers, if they got reformatted, because the persistent name
is from "/dev/mapper" not from "/dev/disk/by-uuid", will "return
0" here, not rebuilt.
Should we handle this?
Regards,
Xunlei
+
+ _target=$(echo $_target | cut -d ' ' -f 2)
+ _uuid=$(blkid $_target | awk -F"UUID=" '{print $2}' | cut -d
'"' -f 2)
+ if [[ -z "$_uuid" ]];then
+ echo "Warning: UUID is not present"
+ return 1
+ fi
+
+ echo $_dracut_args | grep $_uuid &> /dev/null
+ #if dracut argument and _target have same uuid, then also do not rebuild
+ [[ $? -ne 0 ]] || return 0
Ditto, "[[ $? -eq 0 ]] && return 0" is more readable, but that's ok
:-)
+
+ echo "Detected change in File System UUID"
+ return 1
+}
+
# returns 0 if system is not modified
# returns 1 if system is modified
# returns 2 if system modification is invalid
@@ -374,6 +407,12 @@ is_system_modified()
return $ret
fi
+ is_fs_uuid_changed
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ return $ret
+ fi
+
return 0
}