#!/bin/bash # echo -e "\033[31mWarning:此程序用于格式化分区! \033[0m" fdisk -l 2>/dev/null |grep -o "^Disk /dev/[sh]d[a-z]"|awk ‘{print $2}‘ read -p "Your choice:" PARTDISK if [ $PARTDISK == ‘quit‘ ]; then echo "quit" exit 5 fi until fdisk -l 2>/dev/null |grep -o "^Disk /dev/[sh]d[a-z]" |grep "^Disk $PARTDISK$" &>/dev/null ;do read -p "错误的选项,请重新选择:" PARTDISK done read -p "磁盘原有数据将损坏,确认(y/n)?:" CHOICE until [ $CHOICE == ‘y‘ -o $CHOICE == ‘n‘ ]; do read -p "Will destroy all data,continue:" CHOICE done if [ $CHOICE == ‘n‘ ]; then echo "Quit" exit 9 else dd if=/dev/zero of=/$PARTDISK bs=512 count=1 sync sleep 3 echo ‘n p 1 1 w‘ |fdisk $PARTDISK &>/dev/null partprobe $PARTDISK sleep 2 mkfs.ext4 $PARTDISK sleep 2 ‘mkdir /`echo $PARTDISK |awk -F/ ‘{print $3}‘|cut -c 3 |tr ‘a-z‘ ‘A-Z‘`‘=‘DIR‘ mount $PARTDISK /$DIR fi
这个是别人的
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin export PATH i=1 while [ $i -lt 13 ] #硬盘数量,除系统盘之外是12块 do j=`echo $i|awk ‘{printf "%c",97+$i}‘` #系统盘是sda,如果是其它的需要修改脚本 parted /dev/sd$j <<FORMAT mklabel gpt mkpart primary 0 -1 ignore quit FORMAT mkfs.ext4 -T largefile /dev/sd${j}1 #格式化磁盘 mkdir /disk${i} mount="/dev/sd${j}1 /disk${i} ext4 defaults 0 0" rm -rf /disk${i}/* echo $mount >>/etc/fstab #写入分区表 i=$(($i+1)) done echo "/n/n*****Formating and Mounting have finished****/n/n" mount -a #挂载
时间: 2024-10-12 16:32:17