Bash script that automatically partitions and formats a hard disk

Source: Internet
Author: User

#!/bin/bash#fdisk-l | grep "^disk/dev/[sh]d[a-z" | awk ' {print $} ' | Sed "[email protected]:@@g" Read-p "Your choice Partdisk above:" partdiskif [$PARTDISK = = Quit];then echo "quit.  ." Exit 0fiuntil Fdisk-l | Grep-o "^disk/dev/[sh]d[a-z]" | grep "^disk ${partdisk}$" &>/dev/null;d o read-p "wrong choice Your Choice again:" Partdiskdone read-p "would des Troy all data continue[y/n]: "choiceuntil [$CHOICE = =" Y "-o $CHOICE = =" n "];d o read-p" would destroy all data continue [y/n]: "choicedone[$CHOICE = = n] && echo" quit ... "&& exit 0;for DISK in ' Mount | grep "/dev/sdb" | awk ' {print $ ';d ofuser-km $DISKumount $DISK && echo "$DISK umount OK" Donedd If=/dev/zero of= $PARTDISK bs=512 C Ount=1&>/dev/nullpartprobe $PARTDISKsync &>/dev/nullsleep 2echo ' np1+20mnp2+512mnp3+128mt382w ' |fdisk $PARTDISK &>/dev/nullpartprobe $PARTDISKsync &>/dev/nullsleep 2mke2fs ${partdisk}1 &>/dev/null && echo "${partdisk}1finished "Sync &>/dev/nullsleep 2mke2fs ${partdisk}2 &>/dev/null && echo" ${partdisk}2finished " Ssync &>/dev/nullsleep 2mkswap ${partdisk}3 &>/dev/null && echo "${partdisk}3finished" Sync & >/dev/nullsleep 2

  

Bash script that automatically partitions and formats a hard disk

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.