脚本功能:显示所有磁盘并选择,将被选择磁盘的分区全部革除,重新划分分区并格式化文件系统
#!/bin/bash
#显示所有磁盘并选择,将被选择磁盘的分区格式化,重新划分分区并格式化文件系统
echo -e "\e[1;34mYou have this disks:\e[0m"
fdisk -l 2> /dev/null | grep -o "^Disk /dev/[sv]d[a-z]"
echo -e "\e[1;31myour choice is:\nthis may destroy your data,you also can choose
<quit>.\e[0m"
read DISK
if [ $DISK == ‘quit‘ ];then
echo
echo "quit."
exit 2
else
until fdisk -l 2> /dev/null | grep -o "^Disk /dev/[sv]d[a-z]" | grep "^D
isk $DISK$" &> /dev/null;do
read -p "Wrong option,Please choose again:" DISK
done
read -p "Dangeous! Are you sure continue:(yes/no) " CON
if [ $CON == ‘no‘ ];then
echo "quit."
exit 3
else
dd if=/dev/zero of=$DISK bs=512 count=1 &> /dev/null
sync
echo ‘
n
p
1
+50M
n
p
2
+50M
n
p
3
+50M
w ‘ | fdisk $DISK &> /dev/null
fi
fi
mke2fs -j ${DISK}1 &> /dev/null
v1=$?
if [ $v1 -eq 0 ];then
echo "make ${DISK}1 succeed. "
fi
sleep 1
mke2fs -j ${DISK}2 &> /dev/null
v2=$?
if [ $v2 -eq 0 ];then
echo "make ${DISK}2 succeed. "
fi
sleep 1
mke2fs -j ${DISK}3 &> /dev/null
v3=$?
if [ $v3 -eq 0 ];then
echo "make ${DISK}3 succeed. "
fi