I had to rename a bunch of logical volumes and filesystems.

This script is based on the lvrename command.

It will go line by line of the fs file formated

cat fs
oldfs01a:newfs01b
oldfs02a:newfs02b
oldfs03a:newfs03b

In my case the lvname and fs were were similar except for the last three characters.

It will umount the fs , rename the lv , rename the mount, rename the /etc/fstab and mount the directory.

Use with caution. Use my tips at your own risk !!

#!/usr/bin/sh

DATE=`date '+%Y.%m.%d_%H.%M.%S'`

cp /etc/hosts /etc/hosts.${DATE}

cat fs | while read line
do

oldfs=`echo ${line} | awk -F: '{print $1}'`
newfs=`echo ${line} | awk -F: '{print $2}'`

mapperinfo=`df -h /var/cache/${oldfs} | grep mapper`

oldlv=`lvs ${mapperinfo} | grep -v LV | awk '{print $1}'`
vgname=`lvs ${mapperinfo} | grep -v LV | awk '{print $2}'`

newlv=`echo ${oldlv} | sed -e "s/${oldfs}/${newfs}/g"`

echo "rename ${oldfs} -> ${newfs}"
sleep 7
#######
df -h /var/cache/${oldfs}

umount /var/cache/${oldfs}

lvrename ${vgname} ${oldlv} ${newlv}

sed -ie "s/${oldfs}/${newfs}/g" /etc/fstab

mv /var/cache/${oldfs} /var/cache/${newfs}

mount /var/cache/${newfs}

df -h /var/cache/${newfs}
echo ""
echo ""
done