new feat: add partition script

This commit is contained in:
Yingjie Wang 2024-04-18 15:54:44 -04:00
parent c45f1362ed
commit f7ccffccf0

32
make-partition.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
# 检查 TARGETDISK 变量是否已定义
if [ -z "$TARGETDISK" ]; then
echo "TARGETDISK is not set. Please run the disk selector script first."
exit 1
fi
# 使用 gum confirm 警告:这将删除目标硬盘上的所有数据
if ! gum confirm --prompt "Warning: This will erase all data on $TARGETDISK. Proceed?"; then
echo "Aborting."
exit 1
fi
# 使用 parted 工具创建新的 GPT 分区表
parted -s "$TARGETDISK" mklabel gpt
# 创建 EFI 分区,大小为 512M后面是系统分区占据剩余空间
parted -s "$TARGETDISK" mkpart primary fat32 1MiB 513MiB
parted -s "$TARGETDISK" set 1 esp on
# 计算起始点,为 513MiB 后的第一个 MiB
parted -s "$TARGETDISK" mkpart primary btrfs 513MiB 100%
# 格式化 EFI 分区为 FAT32
mkfs.fat -F32 "${TARGETDISK}1"
# 格式化系统分区为 Btrfs
mkfs.btrfs "${TARGETDISK}2"
echo "Partitioning and formatting complete."