本文主要是介绍linux系统批量挂载磁盘(磁盘大于2T),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、使用parted进行分区:
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
cp /etc/fstab /etc/fstab.bak
if [ -n "$1" ];then
i=1
while [ $i -lt $1 ]
do
mkdir /disk$i
j=`echo $i|awk '{printf "%c",97+$i}'`
parted /dev/vd$j <<EOF
mklabel gpt
mkpart primary 0 -1
ignore
quit
EOF
echo "/n/n******/dev/vd${j} __was Fdisked! Waiting For 10 Second*****/n/n"
sleep 1s
mkfs.ext4 /dev/vd${j}1
if [ "$?" = "0" ];then
echo "/n/n*****sd${j}1 _________________was Formated, Waiting For.....****/n/n"
fi
let i+=1
sleep 1s
echo "/dev/vd${j}1 /disk$[$i +1] ext4 defaults 0 0" >>/etc/fstab
done
else
echo "parameter err,useage: please input server disk munber"
fi
2、使用fdisk工具脚本:
#!/bin/bash
#Used to fomat 6 disks
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
i=1
while [ $i -lt 4 ]
do
j=`echo $i|awk '{printf "%c",97+$i}'`
fdisk /dev/sd$j <<EOF
n
p
1
w
EOF
echo "/n/n******/dev/sd${j} __was Fdisked! Waiting For 10 Second*****/n/n"
sleep 1s
mkfs.ext4 /dev/sd${j}1
if [ "$?" = "0" ];then
echo "/n/n*****sd${j}1 _________________was Formated, Waiting For 5 Second****/n/n"
fi
let i+=1
sleep 1s
done
touch /test2
mkdir /disk1
mkdir /disk2
mkdir /disk3
cat << ESXU > /test2
/dev/sdb1 /disk1 ext4 defaults 0 0
/dev/sdc1 /disk2 ext4 defaults 0 0
/dev/sdd1 /disk3 ext4 defaults 0 0
ESXU
cat /test2 >> /etc/fstab
mount -a
chmod -R 777 /disk*
这篇关于linux系统批量挂载磁盘(磁盘大于2T)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!