码迷,mamicode.com
首页 > 其他好文 > 详细

自动分区并格式化某块硬盘的BASH脚本

时间:2016-10-28 22:49:16      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:bin   fdisk -l   fuse   user   grep   bash   continue   read   gre   

#!/bin/bash
#

fdisk -l | grep "^Disk /dev/[sh]d[a-z]" | awk  ‘{print $2}‘ | sed "s@:@@g"
read -p "Your choice PARTDISK above:" PARTDISK
if [ $PARTDISK == quit ];then
  echo "quit..."
  exit 0
fi
until fdisk -l | grep -o "^Disk /dev/[sh]d[a-z]" | grep "^Disk ${PARTDISK}$"&>/dev/null ;do
  read -p "wrong choice Your choice again:" PARTDISK
done
  read -p "Will destroy all data continue[y/n]:" CHOICE
until [ $CHOICE == "y" -o $CHOICE == "n" ];do
  read -p "Will destroy all data continue[y/n]:" CHOICE
done
[ $CHOICE == n ] && echo "quit..." && exit 0;
for DISK in `mount | grep "/dev/sdb" | awk ‘{print $1}‘`;do
fuser -km $DISK
umount $DISK && echo "$DISK umount ok"
done
dd if=/dev/zero of=$PARTDISK bs=512 count=1&>/dev/null
partprobe $PARTDISK
sync&>/dev/null
sleep 2
echo ‘n
p
1

+20M
n
p
2

+512M
n
p
3

+128M
t
3
82
w‘|fdisk $PARTDISK &>/dev/null
partprobe $PARTDISK
sync &>/dev/null
sleep 2
mke2fs ${PARTDISK}1 &>/dev/null && echo "${PARTDISK}1finished"
sync &>/dev/null
sleep 2
mke2fs ${PARTDISK}2 &>/dev/null && echo "${PARTDISK}2finished"
ssync &>/dev/null
sleep 2
mkswap ${PARTDISK}3 &>/dev/null && echo "${PARTDISK}3finished"
sync &>/dev/null
sleep 2

  

自动分区并格式化某块硬盘的BASH脚本

标签:bin   fdisk -l   fuse   user   grep   bash   continue   read   gre   

原文地址:http://www.cnblogs.com/jining/p/6009389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!