Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4133d22caf | ||
| 90e0344210 | |||
| 524d4f0500 | |||
| 9e980fd07e | |||
|
|
5ac621db8a | ||
|
|
2bb5bd8223 | ||
|
|
a92e5f05de | ||
|
|
265839faae | ||
|
|
ce05c833e7 |
@@ -8,6 +8,7 @@ GREEN='\e[32m'
|
|||||||
YELLOW='\e[33m'
|
YELLOW='\e[33m'
|
||||||
RESET='\e[0m'
|
RESET='\e[0m'
|
||||||
|
|
||||||
|
|
||||||
# root check
|
# root check
|
||||||
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
|
||||||
@@ -17,6 +18,7 @@ fi
|
|||||||
mount_points=("/dev" "/dev/pts" "/proc" "/sys" "/sys/firmware/efi/efivars" "/run")
|
mount_points=("/dev" "/dev/pts" "/proc" "/sys" "/sys/firmware/efi/efivars" "/run")
|
||||||
NO_WRITE=false
|
NO_WRITE=false
|
||||||
|
|
||||||
|
|
||||||
# arguments
|
# arguments
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case $arg in
|
case $arg in
|
||||||
@@ -24,6 +26,10 @@ for arg in "$@"; do
|
|||||||
NO_WRITE=true
|
NO_WRITE=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--noretable)
|
||||||
|
NO_RETABLE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-h)
|
-h)
|
||||||
printf "%-20s %s\n" "Flags:" "Description:"
|
printf "%-20s %s\n" "Flags:" "Description:"
|
||||||
echo
|
echo
|
||||||
@@ -52,22 +58,62 @@ cleanup() {
|
|||||||
}
|
}
|
||||||
trap 'echo "Status Code: $?"; cleanup;' EXIT
|
trap 'echo "Status Code: $?"; cleanup;' EXIT
|
||||||
|
|
||||||
|
|
||||||
|
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 disk_name="$1"
|
||||||
|
local part_num="$2"
|
||||||
|
|
||||||
|
local part_uuid="$(
|
||||||
|
lsblk -ln -o PATH,PARTUUID $disk_name | awk '$1==$(get_partition $disk_name $part_num) {print $2}'
|
||||||
|
)"
|
||||||
|
|
||||||
|
printf "$part_uuid"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Set your target disk here
|
# Set your target disk here
|
||||||
udevadm trigger
|
udevadm trigger
|
||||||
|
|
||||||
lsblk
|
lsblk
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
read -rp "Enter the target disk (e.g., sda): " disk_suffix
|
read -rp "Enter the target disk (e.g., sda): " disk_suffix
|
||||||
disk_name="/dev/${disk_suffix}"
|
disk_name="/dev/${disk_suffix}"
|
||||||
|
|
||||||
echo "Chose disk $disk_name"
|
echo "Chose disk $disk_name"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $NO_RETABLE == true ]]; then
|
||||||
|
echo -e "${YELLOW}--noretable is specified. Tables will not be erased and no partitions will be created${RESET}"
|
||||||
|
else
|
||||||
|
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 || true
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $NO_WRITE == true ]]; then
|
if [[ $NO_WRITE == true ]]; then
|
||||||
echo -e "${YELLOW}--nowrite is specified no need for Img no disks will be written to${RESET}"
|
echo -e "${YELLOW}--nowrite is specified. No need for Img no disks will be written to${RESET}"
|
||||||
else
|
else
|
||||||
read -rp "Enter the name of the usb partition in /dev/mapper (e.g., sda1): " disk_suffix
|
read -rp "Enter the name of the usb partition in /dev/mapper (e.g., sda1): " disk_suffix
|
||||||
|
|
||||||
@@ -87,27 +133,17 @@ else
|
|||||||
mount $usb_name /mnt/ventoy
|
mount $usb_name /mnt/ventoy
|
||||||
cd /mnt/ventoy/Images
|
cd /mnt/ventoy/Images
|
||||||
|
|
||||||
echo "Writing image to $disk_name..."
|
echo "Writing image to $(get_partition $disk_name "3")..."
|
||||||
lz4 -dc PBX.img.lz4 | dd of=$disk_name status=progress
|
lz4 -dc PBX.img.lz4 | dd of=$(get_partition $disk_name "3") status=progress
|
||||||
|
|
||||||
|
partprobe || true
|
||||||
fi
|
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
|
# Resize physical volume
|
||||||
echo "Resizing physical volume..."
|
echo "Resizing physical volume..."
|
||||||
pvresize ${disk_name}3 || true
|
pvresize $(get_partition $disk_name "3") || true
|
||||||
|
|
||||||
|
|
||||||
# Resize swap and root logical volumes
|
# Resize swap and root logical volumes
|
||||||
echo "Resizing swap and root volumes..."
|
echo "Resizing swap and root volumes..."
|
||||||
@@ -116,18 +152,27 @@ lvresize -l +100%FREE --resizefs PBX-vg/root
|
|||||||
|
|
||||||
|
|
||||||
# Mount restored system for chroot
|
# Mount restored system for chroot
|
||||||
|
mount_path="/mnt/debian"
|
||||||
echo "Mounting restored system..."
|
echo "Mounting restored system..."
|
||||||
mkdir -p /mnt/debian
|
mkdir -p $mount_path
|
||||||
mount /dev/mapper/PBX--vg-root /mnt/debian/
|
mount /dev/mapper/PBX--vg-root $mount_path
|
||||||
mount ${disk_name}2 /mnt/debian/boot
|
mount $(get_partition $disk_name "2") ${mount_path}/boot
|
||||||
mount ${disk_name}1 /mnt/debian/boot/efi
|
mount $(get_partition $disk_name "1") ${mount_path}/boot/efi
|
||||||
|
|
||||||
|
for i in "${mount_points[@]}"; do mount -B $i ${mount_path}${i}; done
|
||||||
|
|
||||||
|
echo "Generating fstab..."
|
||||||
|
boot_uuid=$()
|
||||||
|
|
||||||
|
cp ./fstab.template ${mount_path}/etc/fstab
|
||||||
|
|
||||||
|
sed --in-place "s/boot_uuid/$(get_partuuid $disk_name "2")/g" ${mount_path}/etc/fstab
|
||||||
|
sed --in-place "s/efi_uuid/$(get_partuuid $disk_name "1")/g" ${mount_path}/etc/fstab
|
||||||
|
|
||||||
for i in "${mount_points[@]}"; do mount -B $i /mnt/debian$i; done
|
|
||||||
|
|
||||||
# Chroot and reinstall GRUB
|
# Chroot and reinstall GRUB
|
||||||
echo "Entering chroot to reinstall GRUB..."
|
echo "Entering chroot to reinstall GRUB..."
|
||||||
chroot /mnt/debian /bin/bash -c "
|
chroot $mount_path /bin/bash -c "
|
||||||
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
|
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
|
||||||
update-grub
|
update-grub
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -58,16 +58,12 @@ udevadm trigger
|
|||||||
lsblk
|
lsblk
|
||||||
echo
|
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
|
|
||||||
|
|
||||||
disk_name_0="/dev/${disk_suffix}"
|
read -rp "Enter the target disk (e.g., sda): " disk_suffix
|
||||||
disk_name_1="/dev/${disk_suffix}"
|
disk_name="/dev/${disk_suffix}"
|
||||||
|
|
||||||
echo "Raid0 will be configured on $disk_name_0 and $disk_name_1"
|
echo "Chose disk $disk_name"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [[ $NO_WRITE == true ]]; then
|
if [[ $NO_WRITE == true ]]; then
|
||||||
@@ -86,43 +82,28 @@ else
|
|||||||
exit
|
exit
|
||||||
fi
|
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..."
|
echo "Mounting Ventoy..."
|
||||||
mkdir -p /mnt/ventoy
|
mkdir -p /mnt/ventoy
|
||||||
mount $usb_name /mnt/ventoy
|
mount $usb_name /mnt/ventoy
|
||||||
cd /mnt/ventoy/Images
|
cd /mnt/ventoy/Images
|
||||||
|
|
||||||
echo "Writing image to $disk_name..."
|
echo "Writing image to $disk_name..."
|
||||||
lz4 -dc PBX3.img.lz4 | dd of=$disk_name status=progress
|
lz4 -dc PBX-LVM.img.lz4 | dd of=$disk_name status=progress
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# echo "Repairing partition tables"
|
|
||||||
# sgdisk -e $disk_name
|
# Repartition disk using sgdisk
|
||||||
# sgdisk -v $disk_name
|
echo "Repairing partition tables"
|
||||||
|
sgdisk -e $disk_name
|
||||||
|
sgdisk -v $disk_name
|
||||||
|
|
||||||
partprobe || true
|
partprobe || true
|
||||||
|
|
||||||
# echo "Expanding Partition 3 on $disk_name..."
|
echo "Expanding Partition 3 on $disk_name..."
|
||||||
# sgdisk --delete=3 $disk_name
|
sgdisk --delete=3 $disk_name
|
||||||
# sgdisk --new=3:0:0 --typecode=3:8e00 --change-name=3:"Linux LVM" $disk_name
|
sgdisk --new=3:0:0 --typecode=3:8e00 --change-name=3:"Linux LVM" $disk_name
|
||||||
|
|
||||||
# partprobe || true
|
partprobe || true
|
||||||
|
|
||||||
# Resize physical volume
|
# Resize physical volume
|
||||||
echo "Resizing physical volume..."
|
echo "Resizing physical volume..."
|
||||||
@@ -144,14 +125,11 @@ mount ${disk_name}1 /mnt/debian/boot/efi
|
|||||||
|
|
||||||
for i in "${mount_points[@]}"; do mount -B $i /mnt/debian$i; done
|
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
|
# Chroot and reinstall GRUB
|
||||||
echo "Entering chroot to reinstall GRUB..."
|
echo "Entering chroot to reinstall GRUB..."
|
||||||
chroot /mnt/debian /bin/bash -c "
|
chroot /mnt/debian /bin/bash -c "
|
||||||
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
|
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
|
||||||
update-grub
|
update-grub
|
||||||
update-initramfs -u
|
|
||||||
"
|
"
|
||||||
|
|
||||||
echo -e "${GREEN}Restore and resize complete!${RESET}"
|
echo -e "${GREEN}Restore and resize complete!${RESET}"
|
||||||
|
|||||||
BIN
Image/PBX.img.lz4
LFS
BIN
Image/PBX.img.lz4
LFS
Binary file not shown.
BIN
Image/PBX.img3.lz4
LFS
Normal file
BIN
Image/PBX.img3.lz4
LFS
Normal file
Binary file not shown.
@@ -14,7 +14,7 @@ if [[ $EUID -ne 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Converting to IMG"
|
echo "Converting to IMG"
|
||||||
#qemu-img convert -f qcow2 -O raw PBX.qcow2 PBX.img
|
qemu-img convert -f qcow2 -O raw PBX.qcow2 PBX.img
|
||||||
|
|
||||||
losetup -fP PBX.img
|
losetup -fP PBX.img
|
||||||
loop_device=$(losetup -l | grep "PBX.img" | cut -d ' ' -f1)
|
loop_device=$(losetup -l | grep "PBX.img" | cut -d ' ' -f1)
|
||||||
@@ -28,6 +28,6 @@ sgdisk --delete=3 $loop_device
|
|||||||
sgdisk --new=3:+0:+15G --typecode=3:8e00 --change-name=3:"Linux LVM" $loop_device
|
sgdisk --new=3:+0:+15G --typecode=3:8e00 --change-name=3:"Linux LVM" $loop_device
|
||||||
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
|
dd if=/dev/loop0p3 bs=64M conv=sync status=progress | lz4 -z > ./PBX3.img.lz4
|
||||||
|
|
||||||
#losetup -D
|
losetup -D
|
||||||
|
|||||||
19
fstab.template
Normal file
19
fstab.template
Normal 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/PBX--vg-root / ext4 errors=remount-ro 0 1
|
||||||
|
|
||||||
|
# /boot was on /dev/vda2 during installation
|
||||||
|
UUID=BOOT_UUID /boot ext2 defaults 0 2
|
||||||
|
|
||||||
|
# /boot/efi was on /dev/vda1 during installation
|
||||||
|
UUID=EFI_UUID /boot/efi vfat umask=0077 0 1
|
||||||
|
|
||||||
|
/dev/mapper/PBX--vg-swap_1 none swap sw 0 0
|
||||||
Reference in New Issue
Block a user