磁盘分区脚本
要求
1,列出当前系统上的所有磁盘,让用户选择,并且支持q退出脚本,如果用户选择错误,则让用户重新选择;
2, 用户选择后,自动创建挂载目录,进行自动挂载
#! /bin/bash
echo "the disks exist list:"
fdisk -l |grep '磁盘 /dev/sd[a-z]' //列出所有的磁盘
echo "=================================================="
PS3="chose which disk you want to create:" //变量赋值请选择你想创建的磁盘
select VAR in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit
do
case $VAR in //循环
sda)
fdisk -l /dev/sda
break ;;
sd[b-z])
#create partitions
echo "n
p
w" | fdisk /dev/$VAR
#make filesystem
mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null //格式化
#mount the system
mkdir -p /data/${VAR}"1" &> /dev/null //创建挂载点到/dev/null目录
//自动挂载
echo -e "/dev/${VAR}"1" /data/${VAR}"1" xfs defaults 0 0\n" >> /etc/fstab
mount -a &> /dev/null
break ;;
quit)
break;;
*)
echo "wrong disk,please check again";;
esac
done