From c138fc4bcb33b83ef6d9abc11cc1d7a4d7c98047 Mon Sep 17 00:00:00 2001 From: poslop Date: Thu, 25 Sep 2025 09:21:56 -0500 Subject: [PATCH] renmaed pbx-lvm to pbx --- CloneToDisk.sh | 2 +- CloneToRaid0.sh | 137 +++++++++++++++++++++++++++++++ Image/PBX.img.lz4 | 4 +- Image/auto_extract_partitions.sh | 6 ++ 4 files changed, 146 insertions(+), 3 deletions(-) create mode 100755 CloneToRaid0.sh mode change 100755 => 100644 Image/PBX.img.lz4 create mode 100755 Image/auto_extract_partitions.sh diff --git a/CloneToDisk.sh b/CloneToDisk.sh index 9a3b2f4..57acbdf 100755 --- a/CloneToDisk.sh +++ b/CloneToDisk.sh @@ -88,7 +88,7 @@ else cd /mnt/ventoy/Images echo "Writing image to $disk_name..." - lz4 -dc PBX-LVM.img.lz4 | dd of=$disk_name status=progress + lz4 -dc PBX.img.lz4 | dd of=$disk_name status=progress fi diff --git a/CloneToRaid0.sh b/CloneToRaid0.sh new file mode 100755 index 0000000..9a3b2f4 --- /dev/null +++ b/CloneToRaid0.sh @@ -0,0 +1,137 @@ +#!/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 + +mount_points=("/dev" "/dev/pts" "/proc" "/sys" "/sys/firmware/efi/efivars" "/run") +NO_WRITE=false + +# arguments +for arg in "$@"; do + case $arg in + --nowrite) + NO_WRITE=true + shift + ;; + -h) + printf "%-20s %s\n" "Flags:" "Description:" + echo + printf "%-20s %s\n" "--nowrite" "Disables Writing to Disk only modifys Existing Partitions" + exit 1 + ;; + *) + echo "Unknown option: $arg" + echo "Try -h" + exit 1 + ;; + esac +done + + +cleanup() { + echo "Cleaning Mounts" + + umount -lf /mnt/ventoy 2>/dev/null || true + + for i in "${mount_points[@]}"; do umount -lf "/mnt/debian$i" 2>/dev/null || true; done + + umount -lf /mnt/debian/boot/efi 2>/dev/null || true + umount -lf /mnt/debian/boot 2>/dev/null || true + umount -lf /mnt/debian 2>/dev/null || true +} +trap 'echo "Status Code: $?"; cleanup;' EXIT + +# Set your target disk here +udevadm trigger + +lsblk +echo + + + +read -rp "Enter the target disk (e.g., sda): " disk_suffix +disk_name="/dev/${disk_suffix}" + +echo "Chose disk $disk_name" +echo + +if [[ $NO_WRITE == true ]]; then + echo -e "${YELLOW}--nowrite is specified no need for Img no disks will be written to${RESET}" +else + read -rp "Enter the name of the usb partition in /dev/mapper (e.g., sda1): " disk_suffix + + usb_name="/dev/mapper/${disk_suffix}" + + user_response="n" + + read -rp "$(echo -e "${RED}You are about to WRITE and ERASE disk ${disk_name} | Are you sure? y/N: ${RESET}")" user_response + + if [[ $user_response != y ]]; then + echo "Exiting script" + exit + fi + + 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 +fi + + +# Repartition disk using sgdisk +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 + +partprobe || true + +# Resize physical volume +echo "Resizing physical volume..." +pvresize ${disk_name}3 || true + +# Resize swap and root logical volumes +echo "Resizing swap and root volumes..." +lvresize -L +7G PBX-vg/swap_1 +lvresize -l +100%FREE --resizefs PBX-vg/root + + +# Mount restored system for chroot +echo "Mounting restored system..." +mkdir -p /mnt/debian +mount /dev/mapper/PBX--vg-root /mnt/debian/ +mount ${disk_name}2 /mnt/debian/boot +mount ${disk_name}1 /mnt/debian/boot/efi + + +for i in "${mount_points[@]}"; do mount -B $i /mnt/debian$i; done + +# 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 +" + +echo -e "${GREEN}Restore and resize complete!${RESET}" + +cleanup diff --git a/Image/PBX.img.lz4 b/Image/PBX.img.lz4 old mode 100755 new mode 100644 index 0563607..62cec8b --- a/Image/PBX.img.lz4 +++ b/Image/PBX.img.lz4 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:83e61350db442ca7d4fcf171c23bbe2870392babf5d3b4e417181629f0798e76 -size 7802261467 +oid sha256:0bb94626e3a51df1a374c3123ee3746c6920beeb3172de2c74966dea6b2d475d +size 7809018129 diff --git a/Image/auto_extract_partitions.sh b/Image/auto_extract_partitions.sh new file mode 100755 index 0000000..82575d6 --- /dev/null +++ b/Image/auto_extract_partitions.sh @@ -0,0 +1,6 @@ + +#!/bin/bash + +IMAGE="PBX.img" + +fdisk -l ./PBX.img | grep 'PBX\.img[0-9]'