Feature: Clean Orphan LVM without CEPH (#1974)

This commit is contained in:
CanbiZ 2025-02-03 11:57:39 +01:00 committed by GitHub
parent 55c1f2f3dc
commit 50ffcd4734
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,26 +22,18 @@ function find_orphaned_lvm {
orphaned_volumes=() orphaned_volumes=()
while read -r lv vg size; do while read -r lv vg size; do
container_id=$(echo "$lv" | grep -oE "[0-9]+" | head -1) # Exclude system-critical LVs and Ceph OSDs
if [[ "$lv" == "data" || "$lv" == "root" || "$lv" == "swap" || "$lv" =~ ^osd-block- ]]; then
# Exclude system-critical LVs
if [[ "$lv" == "data" || "$lv" == "root" || "$lv" == "swap" ]]; then
continue continue
fi fi
container_id=$(echo "$lv" | grep -oE "[0-9]+" | head -1)
# Check if the ID exists as a VM or LXC container # Check if the ID exists as a VM or LXC container
if [ -f "/etc/pve/lxc/${container_id}.conf" ] || [ -f "/etc/pve/qemu-server/${container_id}.conf" ]; then if [ -f "/etc/pve/lxc/${container_id}.conf" ] || [ -f "/etc/pve/qemu-server/${container_id}.conf" ]; then
continue continue
fi fi
orphaned_volumes+=("$lv" "$vg" "$size") orphaned_volumes+=("$lv" "$vg" "$size")
done < <(lvs --noheadings -o lv_name,vg_name,lv_size --separator ' ' | awk '{print $1, $2, $3}') done < <(lvs --noheadings -o lv_name,vg_name,lv_size --separator ' ' | awk '{print $1, $2, $3}')
if [ ${#orphaned_volumes[@]} -eq 0 ]; then
echo -e "✅ No orphaned LVM volumes found.\n"
exit 0
fi
# Display orphaned volumes # Display orphaned volumes
echo -e "❗ The following orphaned LVM volumes were found:\n" echo -e "❗ The following orphaned LVM volumes were found:\n"
printf "%-25s %-10s %-10s\n" "LV Name" "VG" "Size" printf "%-25s %-10s %-10s\n" "LV Name" "VG" "Size"