Experimenting with patitions

This commit is contained in:
poslop
2025-09-26 13:07:56 -05:00
parent e2fb042e80
commit 548475e013
4 changed files with 69 additions and 19 deletions

View File

@@ -58,12 +58,16 @@ udevadm trigger
lsblk
echo
echo "Enter disk 1 for raid (e.g., sdb): "
read disk_0_suffix
echo "Enter disk 2 for raid (e.g., sdc): "
read disk_1_suffix
read -rp "Enter the target disk (e.g., sda): " disk_suffix
disk_name="/dev/${disk_suffix}"
disk_name_0="/dev/${disk_suffix}"
disk_name_1="/dev/${disk_suffix}"
echo "Chose disk $disk_name"
echo "Raid0 will be configured on $disk_name_0 and $disk_name_1"
echo
if [[ $NO_WRITE == true ]]; then
@@ -82,28 +86,43 @@ else
exit
fi
for disk in "$disk_name_0" "$disk_name_1"; do
echo "Partitioning $disk..."
sgdisk --zap-all "$disk"
sgdisk -n 1:0:+512M -t 1:ef00 -c 1:"EFI System" "$disk"
sgdisk -n 2:0:+1G -t 2:8300 -c 2:"Boot" "$disk"
sgdisk -n 3:0:0 -t 3:8300 -c 3:"Root" "$disk"
done
mdadm --create /dev/md0 --level=1 --raid-devices=2 "${disk_name_0}2" "${disk_name_1}2"
mdadm --create /dev/md1 --level=1 --raid-devices=2 "${disk_name_0}3" "${disk_name_1}3"
disk_name=/dev/md1
echo "Mounting Ventoy..."
mkdir -p /mnt/ventoy
mount $usb_name /mnt/ventoy
cd /mnt/ventoy/Images
echo "Writing image to $disk_name..."
lz4 -dc PBX-LVM.img.lz4 | dd of=$disk_name status=progress
lz4 -dc PBX3.img.lz4 | dd of=$disk_name status=progress
fi
# Repartition disk using sgdisk
echo "Repairing partition tables"
sgdisk -e $disk_name
sgdisk -v $disk_name
# echo "Repairing partition tables"
# sgdisk -e $disk_name
# sgdisk -v $disk_name
partprobe || true
echo "Expanding Partition 3 on $disk_name..."
sgdisk --delete=3 $disk_name
sgdisk --new=3:0:0 --typecode=3:8e00 --change-name=3:"Linux LVM" $disk_name
# echo "Expanding Partition 3 on $disk_name..."
# sgdisk --delete=3 $disk_name
# sgdisk --new=3:0:0 --typecode=3:8e00 --change-name=3:"Linux LVM" $disk_name
partprobe || true
# partprobe || true
# Resize physical volume
echo "Resizing physical volume..."
@@ -125,11 +144,14 @@ mount ${disk_name}1 /mnt/debian/boot/efi
for i in "${mount_points[@]}"; do mount -B $i /mnt/debian$i; done
mdadm --detail --scan >> /mnt/debian/etc/mdadm/mdadm.conf
# Chroot and reinstall GRUB
echo "Entering chroot to reinstall GRUB..."
chroot /mnt/debian /bin/bash -c "
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
update-grub
update-initramfs -u
"
echo -e "${GREEN}Restore and resize complete!${RESET}"