磁盘自动化均等分区:
<span style="font-family:Courier New;font-size:12px;">#!/usr/bin/env sh
set -e
function help()
{
echo "Usage: create_disk_partition <dev-name> <partition-num>"
echo "Help options:"
echo " <dev-name> the name of disk-dev , /dev/sde"
echo " <partition-num> the total num of partition"
echo " -h|? :Show this help message"
}
dev_name=/dev/sde
part_num=36
cylinders_per=0
function format_disk_prepare()
{
toatl_cylinders=`fdisk -l $dev_name | grep "sectors/track" | awk '{print$5}'`
cylinders_per=`expr $toatl_cylinders / $part_num`
cylinders_per=`expr $cylinders_per - 1`
echo "Clear $dev_name data!"
echo ""
echo "o
n
e
1
w"|fdisk $dev_name &> /dev/null
}
function disk_partitioning()
{
iter=0
rm -rf /tmp/part_conf
while [ $iter -lt $part_num ]
do
echo "n
l
+$cylinders_per">>/tmp/part_conf
let iter+=1
done
echo w>>/tmp/part_conf
echo "Partition Start, Please wait for a minute!"
echo ""
cat /tmp/part_conf|fdisk $dev_name &> /dev/null
rm -rf /tmp/part_conf
echo "Congratulation Partition Complete!"
}
function main()
{
format_disk_prepare
disk_partitioning
}
if [ "$1" == "-h" ] || [ "$1" == "?" ] || [ "$1" == "-?" ] || [ "$1" == "--help" ] || [ "$#" == 0 ] || [ "$#" == 1 ]; then
help
exit 1
fi
dev_name=$1
part_num=$2
if test -b $dev_name
then
if test $part_num -le 48 && test $part_num -ge 1
then
main
else
echo -e '\033[41;33;1mError: The partnum must between 1 and 48 !\033[0m'
fi
else
echo -e '\033[41;33;1mError: The device Not Found!\033[0m'
exit 1
fi
</span>