首页 > 代码库 > 自动分区并格式化某块硬盘的BASH脚本
自动分区并格式化某块硬盘的BASH脚本
#!/bin/bash # fdisk -l | grep "^Disk /dev/[sh]d[a-z]" | awk ‘{print $2}‘ | sed "s@:@@g" read -p "Your choice PARTDISK above:" PARTDISK if [ $PARTDISK == quit ];then echo "quit..." exit 0 fi until fdisk -l | grep -o "^Disk /dev/[sh]d[a-z]" | grep "^Disk ${PARTDISK}$"&>/dev/null ;do read -p "wrong choice Your choice again:" PARTDISK done read -p "Will destroy all data continue[y/n]:" CHOICE until [ $CHOICE == "y" -o $CHOICE == "n" ];do read -p "Will destroy all data continue[y/n]:" CHOICE done [ $CHOICE == n ] && echo "quit..." && exit 0; for DISK in `mount | grep "/dev/sdb" | awk ‘{print $1}‘`;do fuser -km $DISK umount $DISK && echo "$DISK umount ok" done dd if=/dev/zero of=$PARTDISK bs=512 count=1&>/dev/null partprobe $PARTDISK sync&>/dev/null sleep 2 echo ‘n p 1 +20M n p 2 +512M n p 3 +128M t 3 82 w‘|fdisk $PARTDISK &>/dev/null partprobe $PARTDISK sync &>/dev/null sleep 2 mke2fs ${PARTDISK}1 &>/dev/null && echo "${PARTDISK}1finished" sync &>/dev/null sleep 2 mke2fs ${PARTDISK}2 &>/dev/null && echo "${PARTDISK}2finished" ssync &>/dev/null sleep 2 mkswap ${PARTDISK}3 &>/dev/null && echo "${PARTDISK}3finished" sync &>/dev/null sleep 2
自动分区并格式化某块硬盘的BASH脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。