Marco Education Video Learning note-shell script complete disk partition formatting

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.