#!/bin/bash

#this script for LVM

echo "Initial a disk..." 

echo -e "\033[31mWarning: \033[0m"

fdisk -l | grep -o "^Disk /dev/[sv]d[a-z]"

read -p "What's disk Your choice:" DISK

if [ "$DISK" == 'quit' ] || [ "$DISK" == 'q' ]; then
echo "quit"
exit 7

fi

######################Check input ################################

until fdisk -l | grep -o "^Disk /dev/[sv]d[a-z]" | grep "^Disk $DISK$" &> /dev/null;do
read -p "Wrong option,your choice again:" DISK
if [ $DISK == quit ] ; then
echo "quit"
exit 7
fi

done

########################Check mount#############################

if mount | grep "$DISK" &> /dev/null;then
echo `mount | grep "^$DISK" | awk '{print $1}'` is busy
read -p "Will you continue?" CHOICE 
until [ $CHOICE == 'y' -o $CHOICE == 'n' ] ; do
read -p "wrong choice ,please try again:" CHOICE
done
if [ $CHOICE == 'n' ] ;then
echo "$DISK is busy,initial disk stop..."
exit 9
else
for I in `mount | grep "$DISK" | awk '{print $1}'`;do
fuser -km $I
umount $I
echo "$I umount ok"
done

######################Continue building disk?##########################
read -p "will destroy all data, continue?" CHOICE
until [ $CHOICE == 'y' -o $CHOICE == 'n' ] ; do
read -p "wrong choice ,please try again:" CHOICE
done
if [ $CHOICE == 'n' ] ;then
echo "$DISK have exist data,initial disk stop..."
exit 9
else
dd if=/dev/zero of=$DISK bs=512 count=1
sync

    sleep 3

#######################fdisk $DISK##############################
echo 'n

p

1

t

8e

w' | fdisk -cu $DISK &> /dev/null
sleep 2
fi
fi

else
echo 'n

p

1

t

8e

w' | fdisk -cu $DISK &> /dev/null
sleep 2

fi

#####################initial disk #################################### 

read -p "Do you want to initial? " INITIAL

{
[ $INITIAL == Y ] || [ $INITIAL == y ] || [ $INITIAL == 'YES' ] || [ $INITIAL == 'yes' ] 

} && {
read -p "Please input vg_disk: " VG_DISK
read -p "Please input lv_disk: " LV_DISK
read -p "Please input lvs_disk's size: " LVS_SIZE
read -p "Please input File system type: " LVS_TYPE
pvcreate ${DISK}1  >/dev/null 2>&1
vgcreate $VG_DISK ${DISK}1 > /dev/null 2>&1
lvcreate -L $LVS_SIZE -n $LV_DISK $VG_DISK  > /dev/null 2>&1
mkfs.$LVS_TYPE /dev/$VG_DISK/$LV_DISK  > /dev/null 2>&1

##########################mount disk###################################
read -p "Do you want to mount now: " LVS_MOUNT  
{
[ $LVS_MOUNT == Y ] || [ $LVS_MOUNT == y ] || [ $LVS_MOUNT == 'YES' ] || [ $LVS_MOUNT == 'yes' ]
} && {
read -p "Please input mount point: " LVS_POINT
[ -d ${LVS_POINT} ] ||  mkdir -p ${LVS_POINT}
echo "/dev/$VG_DISK/$LV_DISK     ${LVS_POINT}   $LVS_TYPE     defaults   0 0  " >> /etc/fstab 
mount -a 
} || exit 

} || exit

最新文章

  1. [原创]java WEB学习笔记105:Spring学习---AOP介绍,相关概念,使用AOP,利用 方法签名 编写 AspectJ 切入点表达式
  2. lecture9-提高模型泛化能力的方法
  3. CF360B Levko and Array (二分查找+DP)
  4. 深入学习Heritrix---解析处理器(Processor)(转)
  5. IE 、Firefox、Chrome 浏览器在 F12 控制台下切换至不同框架介绍
  6. 从零开始学习jQuery (七) jQuery动画-让页面动起来!
  7. Spring aop 小例子demo
  8. 关于EsayUI中datagrid重复提交后台查询数据的问题
  9. Health Check - 每天5分钟玩转 Docker 容器技术(142)
  10. Android--APP性能测试工具GT的使用总结
  11. [Abp 源码分析]八、缓存管理
  12. [zz]蟑螂蚂蚁蚊子已不住在我家了!这个方法100%见效…
  13. mac显示影藏文件
  14. python接口自动化20-requests获取响应时间(elapsed)与超时(timeout) ok试了 获取响应时间的
  15. 【arc093f】Dark Horse(容斥原理,动态规划,状态压缩)
  16. ReactNative——UI1.登录界面样式设置
  17. Docker+Kubernetes(k8s)微服务容器化实践
  18. Hive之GROUP BY详解
  19. GDAL2.0编译——32位和64位
  20. Netstat 的 10 个基本用法

热门文章

  1. msvcr100.dll丢失原因及解决方法
  2. [转]Activitys, Threads, & Memory Leaks
  3. functions and closures are reference types-函数和闭包是引用类型
  4. nodejs中的fiber(纤程)库详解
  5. nodejs使用request和bluebird编写的http请求模块
  6. js 实现图片无限横向滚动效果
  7. 第21章 DMA—直接存储区访问
  8. Linux 常用命令整理
  9. 苹果内购小结 - iOS
  10. .Net core 使用TimeJob