parted自动分区,仅供参考
#!/bin/bash
disk="/dev/nvme0n1"
partition_name="p"
existing_partitions=$(lsblk -n -o NAME "$disk" | wc -l)
if [ "$existing_partitions" -gt 1 ]; then
read -p "该磁盘已经存在分区,是否还要继续并格式化磁盘? (y/n): " choice
if [ "$choice" != "y" ]; then
echo "Operation aborted."
exit 1
fi
fi
parted -s $disk mklabel gpt
sleep 3
disk_part=$(printf "%s 2d" "$parttition_name" $i)
for i in {1..12}
do
parted -s $disk mkpart primary ext4 $((($i-1)*10))G $((($i)*10))G name $disk_part 2>/dev/null
sleep 6
done
echo "磁盘分区已完成"