Persistent device name is an uuid in directory /dev/disk/by-uuid which
can determine the unique devices by soft link. The uuid is created, once
the device are formated by command mkfs, and one filesystem has an
unique uuid to detect itself.
For btrfs, one filesystem may contain several devices. So it may fail to
find the device from the /dev/disk/by-uuid as usual, because
/dev/disk/by-uuid/* only points to the one of the several devices by the
soft link, although there is a filesystem on the devices.
In order to get the persistent device, we can use command "blkid",
instead of finding it in directory /dev/disk/by-uuid directly.
Signed-off-by: Minfei Huang <mhuang(a)redhat.com>
---
v1:
- describe the commit log more detail
---
mkdumprd | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/mkdumprd b/mkdumprd
index 8cf3c7b..52d560e 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -30,14 +30,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
@@ -45,6 +45,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
}
--
1.9.3