Compare commits
2 Commits
4af9cb4a30
...
1e608196a5
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e608196a5 | |||
| 4e3f5a158e |
+9
-25
@@ -7,6 +7,7 @@ YELLOW='\e[33m'
|
|||||||
RESET='\e[0m'
|
RESET='\e[0m'
|
||||||
|
|
||||||
MOUNT_POINTS=("/dev" "/dev/pts" "/proc" "/sys" "/sys/firmware/efi/efivars" "/run")
|
MOUNT_POINTS=("/dev" "/dev/pts" "/proc" "/sys" "/sys/firmware/efi/efivars" "/run")
|
||||||
|
IMG_FILE="PBX.img3.lz4"
|
||||||
NO_WRITE=false
|
NO_WRITE=false
|
||||||
NO_RETABLE=false
|
NO_RETABLE=false
|
||||||
NO_USB=false
|
NO_USB=false
|
||||||
@@ -93,38 +94,21 @@ update-grub
|
|||||||
echo -e "${GREEN}Restore and resize complete!${RESET}"
|
echo -e "${GREEN}Restore and resize complete!${RESET}"
|
||||||
}
|
}
|
||||||
|
|
||||||
write_image() {
|
write_img() {
|
||||||
if [[ $NO_USB == true ]]; then
|
img_file_dir="null"
|
||||||
echo "Writing image to $(get_partition $disk_name "3")..."
|
|
||||||
lz4 -dc ./Image/PBX.img3.lz4 | dd of=$(get_partition $disk_name "3") status=progress
|
|
||||||
|
|
||||||
partprobe || true
|
|
||||||
|
|
||||||
|
if [[ -f "./${IMG_FILE}" ]]; then
|
||||||
|
img_file_dir="./${IMG_FILE}"
|
||||||
|
elif [[ ! -f "./Image/${IMG_FILE}" ]]; then
|
||||||
|
img_file_dir="./Image/${IMG_FILE}"
|
||||||
else
|
else
|
||||||
read -rp "Enter the name of the usb partition in /dev/mapper (e.g., sda1): " disk_suffix
|
img_file_dir="null"
|
||||||
|
|
||||||
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
|
fi
|
||||||
|
|
||||||
echo "Mounting Ventoy..."
|
|
||||||
mkdir -p /mnt/ventoy
|
|
||||||
mount $usb_name /mnt/ventoy
|
|
||||||
cd /mnt/ventoy/Images
|
|
||||||
|
|
||||||
echo "Writing image to $(get_partition $disk_name "3")..."
|
echo "Writing image to $(get_partition $disk_name "3")..."
|
||||||
lz4 -dc PBX.img.lz4 | dd of=$(get_partition $disk_name "3") status=progress
|
|
||||||
|
|
||||||
|
lz4 -dc ${img_file_dir} | dd of=$(get_partition $disk_name "3") status=progress
|
||||||
partprobe || true
|
partprobe || true
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rewrite_gpt_table() {
|
rewrite_gpt_table() {
|
||||||
|
|||||||
@@ -1,33 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# THE RAINBOW HAHAHAH
|
|
||||||
RED='\e[31m'
|
RED='\e[31m'
|
||||||
GREEN='\e[32m'
|
GREEN='\e[32m'
|
||||||
YELLOW='\e[33m'
|
YELLOW='\e[33m'
|
||||||
RESET='\e[0m'
|
RESET='\e[0m'
|
||||||
|
|
||||||
# root check
|
img_file="PBX-Test.img"
|
||||||
|
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo -e "${RED}You must be root to do this." 1>&2
|
echo -e "${RED}You must be root to do this." 1>&2
|
||||||
exit 100
|
exit 100
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Converting to IMG"
|
losetup -fP $img_file
|
||||||
qemu-img convert -f qcow2 -O raw PBX.qcow2 PBX.img
|
loop_device=$(losetup -l | grep $img_file | cut -d ' ' -f1)
|
||||||
|
|
||||||
losetup -fP PBX.img
|
|
||||||
loop_device=$(losetup -l | grep "PBX.img" | cut -d ' ' -f1)
|
|
||||||
echo $loop_device
|
echo $loop_device
|
||||||
|
|
||||||
vgchange -a y PBX-vg
|
vgchange -a y PBX-vg
|
||||||
lvreduce -L 14G -r PBX-vg/root
|
|
||||||
lvreduce -L 976M PBX-vg/swap_1
|
|
||||||
|
|
||||||
sgdisk --delete=3 $loop_device
|
lvreduce -L 12G -r PBX-vg/root
|
||||||
sgdisk --new=3:+0:+15G --typecode=3:8e00 --change-name=3:"Linux LVM" $loop_device
|
|
||||||
|
partclone.ext4 -c -s /dev/mapper/PBX--vg-root | lz4 -z >./PBX-root.img.lz4
|
||||||
|
|
||||||
vgchange -a n PBX-vg
|
vgchange -a n PBX-vg
|
||||||
|
|
||||||
dd if=/dev/loop0p3 bs=64M conv=sync status=progress | lz4 -z > ./PBX3.img.lz4
|
|
||||||
|
|
||||||
losetup -D
|
losetup -D
|
||||||
|
|||||||
Reference in New Issue
Block a user