One filesystem has an unique uuid to detect itself. For btrfs, several diskes can have the same uuid, and the soft link /dev/disk/by-uuid/$uuid points the only one disk which is contained in the btrfs.
It may fails to filter out the disk by uuid, although there is a filesystem on the disk, like btrfs.
In order to get the persistent device, we can use command "blkid".
Signed-off-by: Minfei Huang mhuang@redhat.com --- mkdumprd | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/mkdumprd b/mkdumprd index 4d251ba..5fb578b 100644 --- a/mkdumprd +++ b/mkdumprd @@ -27,14 +27,14 @@ perror() { }
get_persistent_dev() { - local i _tmp _dev + local i _tmp _dev _uuid
_dev=$(udevadm info --query=name --name="$1" 2>/dev/null) [ -z "$_dev" ] && { perror_exit "Kernel dev name of $1 is not found." }
- for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do + for i in /dev/mapper/* /dev/disk/by-id/*; do _tmp=$(udevadm info --query=name --name="$i" 2>/dev/null) if [ "$_tmp" = "$_dev" ]; then echo $i @@ -42,6 +42,18 @@ get_persistent_dev() { fi done
+ if [ "x" != "x""$(blkid $1 | grep "UUID")" ]; then + _uuid=`blkid $1 | grep "UUID" | awk '{print $2}'` + _uuid=${_uuid#*"} + _uuid=${_uuid%"*} + _dev=/dev/disk/by-uuid/$_uuid + _tmp=$(udevadm info --query=name --name=$_dev 2>/dev/null) + if [ "x" != "x"$_tmp ]; then + echo $_dev + return + fi + fi + perror "WARNING: Persistent device name of $1 not found. Using $1 as dump target name" echo $1 }