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

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
PBX.img
PBX.qcow2
PBX-Test.qcow2
*.snapshot*

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}"

View File

@@ -1,6 +0,0 @@
#!/bin/bash
IMAGE="PBX.img"
fdisk -l ./PBX.img | grep 'PBX\.img[0-9]'

33
Image/extract_partition.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
set -e
# THE RAINBOW HAHAHAH
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
RESET='\e[0m'
# root check
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}You must be root to do this." 1>&2
exit 100
fi
echo "Converting to IMG"
#qemu-img convert -f qcow2 -O raw PBX.qcow2 PBX.img
losetup -fP PBX.img
loop_device=$(losetup -l | grep "PBX.img" | cut -d ' ' -f1)
echo $loop_device
vgchange -a y PBX-vg
lvreduce -L 14G -r PBX-vg/root
lvreduce -L 976M PBX-vg/swap_1
sgdisk --delete=3 $loop_device
sgdisk --new=3:+0:+15G --typecode=3:8e00 --change-name=3:"Linux LVM" $loop_device
vgchange -a n PBX-vg
#dd if=/dev/loop0p3 bs=64M conv=sync status=progress | lz4 -z > ./PBX3.img.lz4
#losetup -D