From 2bb5bd822397b4f3c041e708e7cb6439ab125ba0 Mon Sep 17 00:00:00 2001 From: poslop Date: Fri, 16 Jan 2026 18:29:37 -0600 Subject: [PATCH] extract partitions --- .gitignore | 1 + Image/auto_extract_partitions.sh | 6 ------ Image/extract_partition.sh | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) delete mode 100755 Image/auto_extract_partitions.sh create mode 100755 Image/extract_partition.sh diff --git a/.gitignore b/.gitignore index a1205f2..0a73a3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ PBX.img PBX.qcow2 PBX-Test.qcow2 +*.snapshot* diff --git a/Image/auto_extract_partitions.sh b/Image/auto_extract_partitions.sh deleted file mode 100755 index 82575d6..0000000 --- a/Image/auto_extract_partitions.sh +++ /dev/null @@ -1,6 +0,0 @@ - -#!/bin/bash - -IMAGE="PBX.img" - -fdisk -l ./PBX.img | grep 'PBX\.img[0-9]' diff --git a/Image/extract_partition.sh b/Image/extract_partition.sh new file mode 100755 index 0000000..c1818fa --- /dev/null +++ b/Image/extract_partition.sh @@ -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