#!/bin/bash
# xingkongyuanhang
# ****@****.com
#########################################
#挂在目录
MOUNT_PATH="/data"
#文件系统
FILE_SYSTEM="ext4"
#挂在磁盘名称
MOUNT_DEV="sdb"
##########################################
#判断目录是否存在
if [[ ! -d "$MOUNT_PATH" ]];then
echo "创建目录$MOUNT_PATH "
mkdir -p $MOUNT_PATH
else
echo "目录$MOUNT_PATH 已存在"
fi
#判断磁盘是否存在,格式化,挂在指定目录
if [[ ! -z ` lsblk | grep ${MOUNT_DEV}` ]]; then
echo " ${MOUNT_DEV} 存在"
mkfs.${FILE_SYSTEM} /dev/${MOUNT_DEV}
DEV_UUID=`blkid | grep "${MOUNT_DEV}" | awk '{print $2}'`
echo "$DEV_UUID $MOUNT_PATH ${FILE_SYSTEM} defaults 0 0" >> /etc/fstab
mount -a
else
echo "磁盘 $MOUNT_DEV 不存在"
fi