码迷,mamicode.com
首页 > 系统相关 > 详细

linux创建磁盘分区的脚本文件(创建两个512M和2G的主分区)

时间:2015-06-09 14:04:26      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:linux   create   version   please   

#!/bin/bash
# author: suxinghe
# date: 2015.6.9
# version: 0.0.1
# description: create partions for disk

read -p "please input a disk name:" disk
while :
do
	if [[ $disk =~ /dev/* ]]
	then
		if [ -b $disk ]
		then
			read -p "your choice are $disk, are you sure?(yes/no):" ans1 
			if [ $ans1 == yes ]
			then
				while :
				do
					read -p "are you create partions for this disk, are you sure?(yes/no):" ans2
					if [ $ans2 == yes ]
					then
						echo "n
						p
						1
	
						+512M
						n
						p
						2

						+2G
						w" | fdisk $disk &> /dev/null
						echo -e "\n"
						fdisk -l $disk | grep  "^$disk[1-9]\{1,\}";echo -e "create partions \033[32msuccessful\033[0m";echo "exit..." && exit 0  
					elif [ $ans2 == no ]
					then
						echo "exit..."
						exit 6
					else
						echo "Usage:(yes/no)"
						continue
					fi
				done
			elif [ $ans1 == no ]
			then
				echo "exit...."
				exit 8

			else
				echo "Usage:(yes/no)"
				read -p "please input a disk name:" disk
				continue
			fi
		else
			echo "$disk is not exist,please input a exist device file!"
			read -p "please input a disk name:" disk
			continue
		fi
	else
		echo "$disk is a not device file!"
		read -p "please input a disk name:" disk
		continue

	fi		
done


本文出自 “木屋科技” 博客,请务必保留此出处http://starli.blog.51cto.com/8813574/1659960

linux创建磁盘分区的脚本文件(创建两个512M和2G的主分区)

标签:linux   create   version   please   

原文地址:http://starli.blog.51cto.com/8813574/1659960

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