new feat: auto make partition

This commit is contained in:
Yingjie Wang 2024-04-18 17:27:13 -04:00
parent db914a8bc0
commit 43c2e1ec82
4 changed files with 35 additions and 13 deletions

5
choosedisk.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/env bash
TARGETDISK=$(lsblk -nrpo NAME,TYPE | grep ' disk' | awk '{print $1}' | gum choose)
echo "You have selected: $TARGETDISK"

View File

@ -1,12 +1,14 @@
#! /bin/env bash #! /bin/env bash
# assume that /mnt and /mnt/boot is mounted
TARGET=/mnt TARGET=/mnt
DEVICE=$(findmnt -n -o SOURCE $TARGET | sed 's/\[.*//') DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
UUID=$(blkid -s UUID -o value ${DEVICE})
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" umount -R $TARGET
echo $DIR source $DIR/choosedisk.sh
source ./make-partition.sh
source ./mount-subvol.sh
UUID=$(blkid -s UUID -o value "${TARGETDISK}2")
debootstrap stable $TARGET http://deb.debian.org/debian/ debootstrap stable $TARGET http://deb.debian.org/debian/
@ -24,6 +26,7 @@ echo "export PATH=$PATH:/sbin/" >>$TARGET/root/.bashrc
cp $DIR/chroot-commands.sh $TARGET/root/ cp $DIR/chroot-commands.sh $TARGET/root/
chmod +x $TARGET/root/chroot-commands.sh chmod +x $TARGET/root/chroot-commands.sh
chroot $TARGET /bin/bash -l -c '/root/chroot-commands.sh' chroot $TARGET /bin/bash -l -c '/root/chroot-commands.sh'
rm $TARGET/root/chroot-commands.sh
# fix systemd-boot # fix systemd-boot
for ENTRY in $TARGET/boot/loader/entries/*.conf; do for ENTRY in $TARGET/boot/loader/entries/*.conf; do

13
make-partition.sh Normal file → Executable file
View File

@ -2,14 +2,14 @@
# 检查 TARGETDISK 变量是否已定义 # 检查 TARGETDISK 变量是否已定义
if [ -z "$TARGETDISK" ]; then if [ -z "$TARGETDISK" ]; then
echo "TARGETDISK is not set. Please run the disk selector script first." echo "TARGETDISK is not set. Please run the disk selector script first."
exit 1 exit 1
fi fi
# 使用 gum confirm 警告:这将删除目标硬盘上的所有数据 # 使用 gum confirm 警告:这将删除目标硬盘上的所有数据
if ! gum confirm --prompt "Warning: This will erase all data on $TARGETDISK. Proceed?"; then if ! gum confirm "Warning: This will erase all data on $TARGETDISK. Proceed?"; then
echo "Aborting." echo "Aborting."
exit 1 exit 1
fi fi
# 使用 parted 工具创建新的 GPT 分区表 # 使用 parted 工具创建新的 GPT 分区表
@ -26,7 +26,6 @@ parted -s "$TARGETDISK" mkpart primary btrfs 513MiB 100%
mkfs.fat -F32 "${TARGETDISK}1" mkfs.fat -F32 "${TARGETDISK}1"
# 格式化系统分区为 Btrfs # 格式化系统分区为 Btrfs
mkfs.btrfs "${TARGETDISK}2" mkfs.btrfs -f "${TARGETDISK}2"
echo "Partitioning and formatting complete." echo "Partitioning and formatting complete."

15
mount-subvol.sh Normal file
View File

@ -0,0 +1,15 @@
mount "${TARGETDISK}2" $TARGET
btrfs subvolume create $TARGET/@
btrfs subvolume create $TARGET/@home
btrfs subvolume create $TARGET/@var_log
umount $TARGET
mount -o defaults,ssd,noatime,compress=zstd,subvol=@ "${TARGETDISK}2" $TARGET
mkdir -p $TARGET/{home,var/log,boot}
mount -o defaults,ssd,noatime,compress=zstd,subvol=@home "${TARGETDISK}2" $TARGET/home
mount -o defaults,ssd,noatime,compress=zstd,subvol=@var_log "${TARGETDISK}2" $TARGET/var/log
mount "${TARGETDISK}1" $TARGET/boot