一、通过管理员选择创建、格式化、挂载新添加的磁盘脚本
#! /bin/bash
echo "=============================="
PS3="chose which disk you want to create:"
select W in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit
do
case $W in
sda)
fdisk -l /dev/sda
break;;
sd[b-z])
zkUsFfoPecho "n
p
w" | fdisk /dev/$W
mkfs.xfs -i size=512 /dev/${W}"1" &>/dev/null
mkdir -p /data/${W}"1" &>/dev/null
echo -e "/dev/${W}"1" /data/${W}"1" xfs defaults 0 0\n" >> /etc/fstab
mount -a &>/dev/null
break;;
quit)
break;;
*)
echo "wrong disk,plwase chesk again";;
esac
done
二、自动创建、格式化、挂载新添加的磁盘脚本
#!/bin/bash
for V in $(ls /dev/sd[b-z])
do
echo -e "n\np\n\n\n\nw\n" |fdisk $V
mkfs.xfs -i size=512 ${V}1 &>/dev/null
sleep 1
M=$(echo "$V" |awk -F "/" '{print $3}')
mkdir -p /data/${M}1 &>/dev/null
echo -e "${V}1 /data/${M}1 xfs defaults 0 0\n" >>/etc/fstab
mount -a &>/dev/null
done
到此这篇关于shell脚本快速创建、格式化、挂载新添加的磁盘实现方法的文章就介绍到这了,更多相关shell脚本挂载新添加的磁盘内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!