#!/bin/bash

echo "现在开始删除逻辑卷"
sleep 2
echo "请输入逻辑卷名称"
read lvm
if [ "$lvm" = "" ];then
   echo "值为空，请检查"
   exit 99
fi
DIR=`df -h | grep -wi $lvm | awk '{print $NF}'`


#临时卸载逻辑卷
umount $DIR
if [ $? -eq 0 ];then
  echo "逻辑卷临时卸载成功"
else
  echo "逻辑卷临时卸载失败，请检查"
  exit 99
fi

#永久卸载，注释掉fstab中相关内容
sed -i "/\/dev\/vg1\/$lvm/d"  /etc/fstab
if [ $? -eq 0 ];then
  echo "逻辑卷卸载成功"
else
  echo "逻辑卷卸载失败，请检查"
  exit 99
fi

#删除逻辑卷
lvremove /dev/vg1/$lvm -y
if [ $? -eq 0 ];then
  echo "逻辑卷删除成功"
else
  echo "逻辑卷删除失败，请检查"
exit 99 
fi
echo "是否删除$DIR目录 yes|no"
read DEL
if [ "$DEL" = yes ];then
  echo "现在删除$DIR目录"
  rm -rf $DIR
  echo "目录删除成功"
else
  echo "不能删除目录，请检查"
fi




