#!/bin/bash# author: suxinghe# date: 2015.6.9# version: 0.0.1# description: create partions for diskread -p "Please input a disk name:" diskwhile :d oif [[ $disk =~ /dev/* ]]thenif [ -b $disk ]thenread -p "your choice are $disk, are you sure?" (yes/no): " ans1 if [ $ans 1 == yes ]thenwhile :d oread -p " is you create partions for this disk, are you sure? (yes/no): " ans2if [ $ans 2 == yes ]thenecho " NP1+512MNP2+2GW " | fdisk $disk &> /dev/nullecho -e "\ n" fdisk -l $disk | grep "^ $disk [1-9]\{1,\}";echo -e "create partions \033[32msuccessful\033[0m"; Echo "Exit ..." && exit 0 elif [ $ans 2 == no ]thenecho "Exit ..." exit 6elseecho "Usage :(yes/no) "continuefidoneelif [ $ans 1 == no ]thenecho " Exit ... "exit 8elseecho "Usage: (yes/no)" read -p "Please input a disk name:" diskcontinuefielseecho "$disk is not exist,please input a exist device file! " read -p "Please input a disk name:" diskcontinuefielseecho "$disk is a not device file! " read -p "Please input a disk name:" diskcontinuefidone
This article is from "Chalet Technology" blog, please make sure to keep this source http://starli.blog.51cto.com/8813574/1659960
Linux Create a disk partition script file (create two 512M and 2G primary partitions)