linux服务器磁盘挂载
脚本(LinuxVGdisk.sh):
echo "查询新增的块设备:"
fdisk -l
DISKNAME=
echo "请输入新增的块设备路径(例:/dev/sdc)(n 跳过该步骤):"
while read var
do
if [ $var != '' ]
then
if [ $var == 'N' ] || [ $var == 'n' ]
then
break
else
DISKNAME=$var
echo "对设备块:("$DISKNAME")进行分区(操作:n、p、Enter、Enter、Enter、w)(分区号默认1):"
fdisk $DISKNAME && break
echo "请重新输入新增的块设备路径(例:/dev/sdc)(n 跳过该步骤):"
fi
fi
done
echo "安装lvm2:"
yum -y install lvm2
DISKNAME=$DISKNAME"1"
echo "新建物理卷("$DISKNAME"):"
pvcreate $DISKNAME
echo "新建卷组VG(默认 myvg),并将物理卷("$DISKNAME")加入 myvg:"
vgcreate myvg $DISKNAME
echo "新建逻辑卷LV(默认逻辑卷名称 mydata):"
echo "请输入逻辑卷大小:"
while read var
do
if [ $var != '' ]
then
lvcreate -L $var -n mydata myvg && break
echo "请重新输入逻辑卷大小:"
fi
done
echo "新建文件系统:"
mkfs.xfs /dev/myvg/mydata
echo "创建文件夹:"
echo "请输入文件夹名称:"
FILENAME=
cd /
while read var
do
if [ $var != '' ]
then
FILENAME=$var
mkdir $var && break
echo "请重新输入文件夹名称:"
fi
done
echo "挂载文件系统:"
mount /dev/myvg/mydata /$FILENAME
echo "自动挂载文件系统:"
echo /dev/myvg/mydata /$FILENAME xfs defaults 0 0 >> /etc/fstab
echo "挂载完成!"