Debootstrap-script/make-partition.sh

33 lines
923 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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."