脚本乐园 磁盘自动化均等分区demo

磁盘自动化均等分区:
<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>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值