Marco Education Video Learning note-shell script complete disk partition formatting-http://edu.51cto.com/lesson/id-28201.html
The following is the script content, the content is relatively simple, do not make a detailed
To prepare a free disk on Linux, how to partition can be changed within the script
#!/bin/bash
#
echo "Initial a disk ..."
Echo-e "\033[31mwarning: \033[0m"
#开始的说明信息, where warning is displayed in a red font
Fdisk-l 2>/dev/null | Grep-o "^disk/dev/[sh]d[a-z]"
#显示所有磁盘设备
Read-p "Your Choice (Disk or quit):" Partdisk
if [$PARTDISK = = ' quit ']; Then
echo "Quit"
Exit 7
Fi
For I in ' Mount | grep "$PARTDISK" | awk ' {print '} ';d o
fuser-km $I
Umount $I
echo "$I umount OK."
Done
Until Fdisk-l 2>/dev/null | Grep-o "^disk/dev/[sh]d[a-z]" | grep "Disk $PARTDISK $" &>/dev/null;do
Read-p "wrong option,your choice again:" Partdisk
Done
Read-p "would destroy all data, continue (Y or N):" CHOICE
until [$CHOICE = = ' y '-o $CHOICE = = ' n ']; Do
Read-p "would destroy all data, continue (Y or N):" CHOICE
Done
if [$CHOICE = = ' n ']; Then
echo "Quit"
Exit 9
Else
DD If=/dev/zero of= $PARTDISK bs=512 count=1 &>/dev/null
Sync
Sleep 3
Echo ' n
P
1
+2g
N
P
2
+3g
N
P
3
+1g
W ' | Fdisk $PARTDISK &>/dev/null
Partprobe $PARTDISK
Sync
Sleep 2
MKFS.EXT4 ${partdisk}1 &>/dev/null
MKFS.EXT4 ${partdisk}2 &>/dev/null
Mkswap ${partdisk}3 &>/dev/null
Fi
Fdisk-l $PARTDISK
#查看分区结果
This article is from the "Wang Liming" blog, make sure to keep this source http://80cto.blog.51cto.com/7503144/1611078
Marco Education Video Learning note-shell script complete disk partition formatting