#!/bin/bash #实现硬盘自动分区助手 echo "当前所有分区:" echo `fdisk -l|grep "Disk /dev/[sh]d"|cut -d: -f1|awk '{print $2 "\t"}'` read -p "请输入你选择的磁盘分区: " DISK until fdisk -l|grep "Disk /dev/[sh]d"|cut -d: -f1|awk '{print $2 "\t"}'|grep $DISK ;do echo "输入错误" exit 7 done FDISK=`fdisk -l|grep "Disk /dev/sdb"|cut -d: -f2|awk '{print $1}'|cut -d "." -f1` echo "您选择的分区是:$DISK,分区大小是:$FDISK" fDISK=$(($FDISK/4)) echo "$fDISK" read -p "分区会导致磁盘损毁的可能,是否继续分区(y/n):" YORNO if [ $YORNO == n -o $YORNO == N ];then echo "脚本退出,不执行格式化操作" elif [ $YORNO == Y -o $YORNO == y ];then echo "删除分区准备" sleep 5 if dd if=/dev/zero of=$DISK bs=512k count=1 ;then echo "删除分区完成" sleep 5 echo "开始分区为4个主分区" echo "n p 1 +"$fDISK"G n p 2 +"$fDISK"G n p 3 +"$fDISK"G n p w"|fdisk $DISK else echo "格式化失败。。。" exit 11 fi else echo "输入错误,请输入Yy OR Nn" exit 10 fi
原创文章,作者:lyy910203,如若转载,请注明出处:http://www.178linux.com/26065