29 Commits
Author SHA1 Message Date
poslop 1d81542e09 Comprehensive README with usage guide and troubleshooting 2026-07-13 14:57:27 -05:00
poslop 002df99e75 clean repo 2026-07-13 14:13:54 -05:00
poslop 40aa387c3c fi 2026-07-13 14:10:29 -05:00
poslop d0fa3f2e47 better warnings 2026-07-13 14:04:42 -05:00
poslop 5d8c3fd3b0 efivars if availible 2026-07-13 13:57:18 -05:00
poslop 3777d25662 fstab changes 2026-07-13 13:44:25 -05:00
poslop 581a827831 fs version improvments 2026-07-13 11:23:39 -05:00
poslop 7d3d6c2216 fstab edits 2026-05-01 11:00:37 -05:00
poslop 89e7f17af6 apt install linux fuckery 2026-04-30 14:09:06 -05:00
poslop 45de18b162 mounts 2026-04-30 11:19:03 -05:00
poslop 0664dde3cb rewrite chroot 2026-04-30 10:32:47 -05:00
poslop 91f41fbfba lvm changes 2026-04-30 10:04:00 -05:00
poslop 27b5bf9aa5 fixed awk and sed 2026-04-29 16:16:36 -05:00
poslop 794ca09dfb AHHHHHHHHHHHHHHh I HATE DEBIUAB U AHTE DEBIAN 2026-04-29 15:37:40 -05:00
poslop f06573af1c echo debugs 2026-04-28 13:21:48 -05:00
poslop 8577cd1176 more refactoring 2026-04-28 12:00:42 -05:00
poslop 31c7e91b91 lvm_init 2026-04-28 08:46:33 -05:00
poslop 1e608196a5 partclone in extract script 2026-04-27 16:01:27 -05:00
poslop 4e3f5a158e Remove USB support 2026-04-27 15:26:47 -05:00
poslop 4af9cb4a30 Convert to functions 2026-04-27 15:00:42 -05:00
poslop 4133d22caf part3 and fstab temp 2026-01-26 10:37:48 -06:00
poslop 90e0344210 tset bump 2026-01-16 23:34:31 -06:00
poslop 524d4f0500 Update README.md 2026-01-16 23:30:41 -06:00
poslop 9e980fd07e Update README.md 2026-01-16 23:27:47 -06:00
poslop 5ac621db8a convert to p3 only writing 2026-01-16 23:12:25 -06:00
poslop 2bb5bd8223 extract partitions 2026-01-16 18:29:37 -06:00
poslop a92e5f05de fixed return 2026-01-16 16:19:40 -06:00
poslop 265839faae fixed parameters of get_partition 2026-01-16 16:00:59 -06:00
poslop ce05c833e7 get_partition 2026-01-16 15:55:04 -06:00
9 changed files with 531 additions and 268 deletions
-1
View File
@@ -1 +0,0 @@
*.lz4 filter=lfs diff=lfs merge=lfs -text
+1 -3
View File
@@ -1,3 +1 @@
PBX.img
PBX.qcow2
PBX-Test.qcow2
*.zst
+290 -118
View File
@@ -1,137 +1,309 @@
#!/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
NO_RETABLE=false
NO_USB=false
NO_CLEANUP=false
IMG_FILE="PBX-Image-*.tar.zst"
MOUNT_PATH="/mnt/debian"
MOUNT_POINTS=("/dev" "/dev/pts" "/proc" "/sys" "/run")
BOOT_PART="NULL"
EFI_PART="NULL"
ROOT_PART="NULL"
VGROUP="SangomaPBX-vg"
ROOT_LV="root"
SWAP_LV="swap_1"
VG_PATH="/dev/mapper/SangomaPBX--vg-"
# 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
case $arg in
--nowrite)
NO_WRITE=true
shift
;;
--noretable)
NO_RETABLE=true
shift
;;
--nocleanup)
NO_CLEANUP=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
main() {
root_check
check_dependencies
udevadm trigger
dialogue
assign_part_var
trap 'echo "Status Code: $?"; cleanup;' EXIT
if [[ $NO_RETABLE == true ]]; then
echo -e "${YELLOW}Option --noretable is specified. Tables will not be erased and no partitions will be created${RESET}"
else
rewrite_gpt_table
assign_part_var
lvm_init
make_filesystem
fi
mount_partitions
write_img
mount_chroot
gen_fstab
install_grub
echo -e "${GREEN}Restore and resize complete!${RESET}"
exit 0
}
root_check() {
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}You must be root to do this." 1>&2
exit 100
fi
}
check_dependencies() {
local missing=()
local required_tools=("sgdisk" "pv" "pvcreate" "vgcreate" "lvcreate" "vgchange" "mkfs.vfat" "mkfs.ext4" "mkswap" "tar" "zstd" "lsblk" "partprobe" "chroot")
for tool in "${required_tools[@]}"; do
if ! command -v "$tool" &>/dev/null; then
missing+=("$tool")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
echo -e "${RED}Missing required tools: ${missing[*]}${RESET}"
echo
echo "Install with:"
echo " apt install gdisk pv lvm2 zstd dosfstools e2fsprogs parted util-linux coreutils"
exit 1
fi
echo -e "${GREEN}All dependencies found${RESET}"
}
dialogue() {
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 == false ]]; then
echo -e "${RED}WARNING: ALL DATA ON ${disk_name} WILL BE DESTROYED${RESET}"
elif [[ $NO_RETABLE == false ]]; then
echo -e "${YELLOW}INFO: Running in NO WRITE mode. No data will be written to disk${RESET}"
else
echo -e "${YELLOW}WARNING: Existing partitions will be used but filesystems and file data may be modified${RESET}"
fi
lsblk $disk_name
echo
read -rp "Are you sure you want to continue? (yes/no): " confirm
if [[ "$confirm" != "yes" ]]; then
echo "Aborted."
exit 0
fi
}
rewrite_gpt_table() {
vgchange -an $VGROUP 2>/dev/null || true
vgremove -f $VGROUP 2>/dev/null || true
pvremove -ff $ROOT_PART 2>/dev/null || true
sgdisk -Z $disk_name
sgdisk -c $disk_name
sgdisk -n 1:1MiB:+512M -t 1:ef00 -c 1:"EFI System" $disk_name
sgdisk -n 2:0:+1G -t 2:8300 -c 2:"boot" $disk_name
sgdisk -n 3:0:0 -t 3:8e00 -c 3:"Linux LVM" $disk_name
partprobe 2>/dev/null ||
lsblk $disk_name
echo -e "${GREEN}GPT table created. ${RESET}"
}
assign_part_var() {
EFI_PART=$(get_partition $disk_name "1")
BOOT_PART=$(get_partition $disk_name "2")
ROOT_PART=$(get_partition $disk_name "3")
}
lvm_init() {
pvcreate $ROOT_PART -ff
vgcreate $VGROUP $ROOT_PART -f
vgchange -ay $VGROUP
lvcreate -L 4G $VGROUP -n swap_1
lvcreate -l 100%FREE $VGROUP -n root
echo -e "${GREEN}LVM initialized ${RESET}"
}
make_filesystem() {
mkfs.vfat -I -F 32 $EFI_PART
mkfs.ext4 -F $BOOT_PART
mkfs.ext4 -F "${VG_PATH}${ROOT_LV}"
mkswap -f "${VG_PATH}${SWAP_LV}"
echo -e "${GREEN}Make filesystems finished.${RESET}"
}
write_img() {
if [[ $NO_WRITE == true ]]; then
echo -e "${YELLOW}Option --nowrite is specified. No need for Img no disks will be written to${RESET}"
return 0
fi
local img_file_dir=$(ls -1 ./PBX-Image-*.tar.zst 2>/dev/null | head -n1)
if [[ -z "$img_file_dir" ]]; then
img_file_dir=$(ls -1 ./Image/PBX-Image-*.tar.zst 2>/dev/null | head -n1)
fi
if [[ -z "$img_file_dir" ]]; then
echo -e "${RED}NO TAR.ZST FILE FOUND${RESET}"
exit 100
fi
echo "Writing image to ${VG_PATH}${ROOT_LV}..."
pv "${img_file_dir}" | tar -I zstd -x -C "${MOUNT_PATH}"
echo -e "${GREEN}Finished writing image to disk${RESET}"
}
get_partition() {
local disk_name="$1"
local part_num="$2"
local part_path="$(
lsblk -lnp -o NAME,TYPE "$disk_name" |
awk '$2=="part"{print $1}' |
sed -n "${part_num}p"
)"
printf "$part_path"
}
get_partuuid() {
local target_part="$1"
blkid -s UUID -o value "$target_part"
}
mount_partitions() {
echo "Mounting partitions..."
vgchange -ay $VGROUP
mkdir -p "${MOUNT_PATH}"
mount "${VG_PATH}${ROOT_LV}" $MOUNT_PATH
mkdir -p "${MOUNT_PATH}/boot"
mount $BOOT_PART "${MOUNT_PATH}/boot"
mkdir -p "${MOUNT_PATH}/boot/efi"
mount $EFI_PART "${MOUNT_PATH}/boot/efi"
}
mount_chroot() {
echo "Mounting restored system..."
for i in "${MOUNT_POINTS[@]}"; do mount --bind -m "$i" "${MOUNT_PATH}${i}"; done
if [[ -d /sys/firmware/efi/efivars ]]; then
mount -t efivarfs efivarfs "${MOUNT_PATH}/sys/firmware/efi/efivars"
fi
echo -e "${GREEN}Mounts prepared for chroot.${RESET}"
}
gen_fstab() {
echo "Generating fstab..."
boot_uuid=$(get_partuuid $BOOT_PART)
efi_uuid=$(get_partuuid $EFI_PART)
cp ./fstab_template ${MOUNT_PATH}/etc/fstab
sed --in-place "s/BOOT_UUID/${boot_uuid}/g" ${MOUNT_PATH}/etc/fstab
sed --in-place "s/EFI_UUID/${efi_uuid}/g" ${MOUNT_PATH}/etc/fstab
echo -e "${GREEN}fstab write complete!${RESET}"
}
install_grub() {
echo "Entering chroot to reinstall GRUB..."
CHROOT_GRUB_INSTALL="grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian"
CHROOT_GRUB_UPDATE="update-grub"
chroot_cmd "$CHROOT_GRUB_INSTALL"
chroot_cmd "$CHROOT_GRUB_UPDATE"
echo -e "${GREEN}Grub installed!${RESET}"
}
chroot_cmd() {
CHROOT_PATH="export PATH=/usr/sbin:/usr/bin:/sbin:/bin"
chroot $MOUNT_PATH /bin/bash -c "${CHROOT_PATH} && ${1}"
}
cleanup() {
echo "Cleaning Mounts"
umount -lf /mnt/ventoy 2>/dev/null || true
if [[ $NO_CLEANUP = true ]]; then
echo -e "${YELLOW}No cleanup specified. Make sure to manually clean mounts.${RESET}" 1>&2
exit 100
fi
for i in "${mount_points[@]}"; do umount -lf "/mnt/debian$i" 2>/dev/null || true; done
echo "Cleaning Mounts"
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
for i in "${MOUNT_POINTS[@]}"; do umount -lf "${MOUNT_PATH}${i}" 2>/dev/null || true; done
umount -lf "${MOUNT_PATH}/boot/efi" 2>/dev/null || true
umount -lf "${MOUNT_PATH}/boot" 2>/dev/null || true
umount -lf "${MOUNT_PATH}" 2>/dev/null || true
vgchange -an $VGROUP
echo -e "${GREEN}Clean.${RESET}"
}
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.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
main
-137
View File
@@ -1,137 +0,0 @@
#!/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
-3
View File
@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0bb94626e3a51df1a374c3123ee3746c6920beeb3172de2c74966dea6b2d475d
size 7809018129
-6
View File
@@ -1,6 +0,0 @@
#!/bin/bash
IMAGE="PBX.img"
fdisk -l ./PBX.img | grep 'PBX\.img[0-9]'
+151
View File
@@ -0,0 +1,151 @@
# PBX Image Script
Fast deployment tool for cloning PBXact/FreePBX systems using tar archives and zstd compression.
## Overview
This tool creates and restores complete PBX system images including:
- Root filesystem with LVM
- Boot partition (ext4)
- EFI system partition (FAT32)
- GRUB bootloader configuration
- fstab generation with proper filesystem UUIDs
## Requirements
**Environment:**
- Live Linux USB (must boot in UEFI mode)
- Root access
**Dependencies:**
```bash
apt install gdisk pv lvm2 zstd dosfstools e2fsprogs parted util-linux coreutils
```
The deployment script checks for missing tools automatically.
## Usage
### 1. Creating an Image
Extract from an existing `.img` file with LVM:
```bash
sudo ./fs_extract.sh
```
**What it does:**
- Mounts the image via loopback
- Activates LVM volume group
- Detects kernel version from `/boot/vmlinuz-*`
- Creates `PBX-Image-<kernel-version>.tar.zst` with progress bar
- Excludes sockets and special files automatically
The resulting archive contains the complete filesystem ready for deployment.
### 2. Deploying to New Hardware
Clone the archive to a target disk:
```bash
sudo ./CloneToDisk.sh
```
**Interactive process:**
1. Shows available disks (`lsblk`)
2. Prompts for target disk (e.g., `sda`, `vdb`)
3. **Requires typing `yes` to confirm** (prevents accidents)
4. Partitions disk (GPT: EFI + boot + LVM)
5. Creates ext4/vfat filesystems
6. Extracts tar archive with progress bar
7. Generates `/etc/fstab` with correct UUIDs
8. Installs GRUB to EFI partition
9. Configures bootloader
**Time:** ~5-10 minutes depending on image size and disk speed.
### Command-Line Options
```bash
./CloneToDisk.sh [options]
--nowrite Skip image extraction (only partition/format)
--noretable Use existing partition table (don't repartition)
--nocleanup Leave filesystems mounted after completion
-h Show help
```
## Partition Layout
Created automatically by `CloneToDisk.sh`:
| Partition | Size | Type | Mount Point | Filesystem |
|-----------|------|------|-------------|------------|
| 1 | 512MB | EFI System | `/boot/efi` | FAT32 |
| 2 | 1GB | Linux | `/boot` | ext4 |
| 3 | Remaining | LVM PV | (LVM) | - |
**LVM Layout** (on partition 3):
| LV | Size | Mount Point | Filesystem |
|----|------|-------------|------------|
| `SangomaPBX-vg/root` | Remaining | `/` | ext4 |
| `SangomaPBX-vg/swap_1` | 4GB | swap | swap |
## Image Storage
**Do not store images in git.**
Images are distributed via [Gitea Releases](https://git.archfox.org/poslop/PBX-Image-Script/releases).
To use:
1. Download the latest `.tar.zst` from releases
2. Place in the same directory as `CloneToDisk.sh`
3. Run the script
## Files
- **`fs_extract.sh`** - Creates image from disk image file
- **`CloneToDisk.sh`** - Deploys image to physical disk
- **`fstab_template`** - Template for generating `/etc/fstab` with UUID placeholders
## Technical Details
**Compression:**
- Uses zstd (fast compression, good ratio)
- Excludes logs, caches, temp files, and sockets
- Typical compression ratio: ~40-60% depending on content
**Boot Configuration:**
- UEFI only (no legacy BIOS support)
- Uses `grub-install` and `update-grub` in chroot
- Mounts `/sys/firmware/efi/efivars` for EFI variable access
- Automatically detects and uses correct kernel version
**Safety Features:**
- Dependency checking before execution
- Explicit confirmation required (`yes` not just `y`)
- Color-coded warnings (red for destructive, yellow for info)
- Cleans up mounts automatically on exit or error
## Troubleshooting
**"NO TAR.ZST FILE FOUND"**
- Download image from releases page
- Place in current directory or `./Image/` subdirectory
**"Missing required tools"**
- Run: `apt install gdisk pv lvm2 zstd dosfstools e2fsprogs parted util-linux coreutils`
**GRUB installation fails**
- Verify you booted the live USB in UEFI mode (not legacy BIOS)
- Check `/sys/firmware/efi/efivars` exists
**Mount errors**
- Use `--nocleanup` to inspect state
- Manually unmount with `umount -lf /mnt/debian/*`
- Deactivate LVM: `vgchange -an SangomaPBX-vg`
## License
Internal tooling for PBXact deployment.
Executable
+70
View File
@@ -0,0 +1,70 @@
#!/bin/bash
set -e
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
RESET='\e[0m'
IMG_FILE="PBX-Test.img"
ROOT_LV_PATH="/dev/mapper/PBX--vg-root"
MOUNT_PATH="/mnt/debian"
VGROUP="PBX-vg"
main() {
root_check
trap 'echo "Status Code: $?"; cleanup;' EXIT
losetup -fP $IMG_FILE
LOOP_DEVICE=$(losetup -l | grep $IMG_FILE | cut -d ' ' -f1)
echo $LOOP_DEVICE
vgchange -a y $VGROUP
mkdir -p $MOUNT_PATH
mount $ROOT_LV_PATH $MOUNT_PATH
mount "${LOOP_DEVICE}p2" "$MOUNT_PATH/boot"
mount "${LOOP_DEVICE}p1" "$MOUNT_PATH/boot/efi"
KERNEL_VERSION=$(get_kernel_version)
tar -I zstd -c -C "${MOUNT_PATH}" --warning=no-file-ignored . | pv >"PBX-Image-${KERNEL_VERSION}.tar.zst"
}
root_check() {
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}You must be root to do this." 1>&2
exit 77
fi
}
get_kernel_version() {
local kernel_file=$(ls -1 "$MOUNT_PATH/boot/vmlinuz-"* 2>/dev/null | head -n1)
if [[ -n "$kernel_file" ]]; then
basename "$kernel_file" | sed 's/vmlinuz-//'
else
echo "unknown"
fi
}
cleanup() {
if [[ $NO_CLEANUP = true ]]; then
echo -e "${YELLOW}No cleanup specified. Make sure to manually clean mounts.${RESET}" 1>&2
exit 100
fi
echo "Cleaning Mounts"
umount -lf "${MOUNT_PATH}/boot/efi" 2>/dev/null || true
umount -lf "${MOUNT_PATH}/boot" 2>/dev/null || true
umount -lf "${MOUNT_PATH}" 2>/dev/null || true
vgchange -a n $VGROUP
echo -e "${GREEN}Clean.${RESET}"
losetup -D
}
main
+19
View File
@@ -0,0 +1,19 @@
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/SangomaPBX--vg-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/vda2 during installation
UUID=BOOT_UUID /boot ext4 defaults 0 2
# /boot/efi was on /dev/vda1 during installation
UUID=EFI_UUID /boot/efi vfat umask=0077 0 1
/dev/mapper/SangomaPBX--vg-swap_1 none swap sw 0 0