From 43c2e1ec8226c3cbbcfbde648e111d8b98537bb7 Mon Sep 17 00:00:00 2001 From: Yingjie Wang Date: Thu, 18 Apr 2024 17:27:13 -0400 Subject: [PATCH] new feat: auto make partition --- choosedisk.sh | 5 +++++ install.sh | 15 +++++++++------ make-partition.sh | 13 ++++++------- mount-subvol.sh | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100755 choosedisk.sh mode change 100644 => 100755 make-partition.sh create mode 100644 mount-subvol.sh diff --git a/choosedisk.sh b/choosedisk.sh new file mode 100755 index 0000000..8bd7928 --- /dev/null +++ b/choosedisk.sh @@ -0,0 +1,5 @@ +#!/bin/env bash + +TARGETDISK=$(lsblk -nrpo NAME,TYPE | grep ' disk' | awk '{print $1}' | gum choose) + +echo "You have selected: $TARGETDISK" diff --git a/install.sh b/install.sh index 63a3e06..f2d1d51 100755 --- a/install.sh +++ b/install.sh @@ -1,12 +1,14 @@ #! /bin/env bash -# assume that /mnt and /mnt/boot is mounted - TARGET=/mnt -DEVICE=$(findmnt -n -o SOURCE $TARGET | sed 's/\[.*//') -UUID=$(blkid -s UUID -o value ${DEVICE}) -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -echo $DIR +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + +umount -R $TARGET +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/ @@ -24,6 +26,7 @@ echo "export PATH=$PATH:/sbin/" >>$TARGET/root/.bashrc cp $DIR/chroot-commands.sh $TARGET/root/ chmod +x $TARGET/root/chroot-commands.sh chroot $TARGET /bin/bash -l -c '/root/chroot-commands.sh' +rm $TARGET/root/chroot-commands.sh # fix systemd-boot for ENTRY in $TARGET/boot/loader/entries/*.conf; do diff --git a/make-partition.sh b/make-partition.sh old mode 100644 new mode 100755 index 7658476..4a22aed --- a/make-partition.sh +++ b/make-partition.sh @@ -2,14 +2,14 @@ # 检查 TARGETDISK 变量是否已定义 if [ -z "$TARGETDISK" ]; then - echo "TARGETDISK is not set. Please run the disk selector script first." - exit 1 + 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 +if ! gum confirm "Warning: This will erase all data on $TARGETDISK. Proceed?"; then + echo "Aborting." + exit 1 fi # 使用 parted 工具创建新的 GPT 分区表 @@ -26,7 +26,6 @@ parted -s "$TARGETDISK" mkpart primary btrfs 513MiB 100% mkfs.fat -F32 "${TARGETDISK}1" # 格式化系统分区为 Btrfs -mkfs.btrfs "${TARGETDISK}2" +mkfs.btrfs -f "${TARGETDISK}2" echo "Partitioning and formatting complete." - diff --git a/mount-subvol.sh b/mount-subvol.sh new file mode 100644 index 0000000..0f65e34 --- /dev/null +++ b/mount-subvol.sh @@ -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