1
0
This commit is contained in:
2026-08-02 10:40:47 -05:00
commit 5f114d9845
19 changed files with 940 additions and 0 deletions

60
07-add-shared-storage.sh Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# Wire the shared storage into the cluster (run once on pve1; datacenter config
# replicates to pve2 automatically):
# - lab-nfs : NFS share from the storage VM
# - lab-lvm : LVM volume group built on the shared iSCSI LUN
set -euo pipefail
source "$(dirname "$0")/lab.env"
has_storage() { lab_ssh "$PVE1_IP" "pvesm status 2>/dev/null | awk '{print \$1}' | grep -qx '$1'"; }
echo "==> Adding NFS storage 'lab-nfs'"
if has_storage lab-nfs; then
echo " already present"
else
lab_ssh "$PVE1_IP" "pvesm add nfs lab-nfs --server ${STORE_IP} --export /srv/nfs \
--content images,iso,vztmpl,backup,rootdir --options vers=4"
fi
echo "==> Adding iSCSI base storage 'lab-iscsi'"
if has_storage lab-iscsi; then
echo " already present"
else
echo " discoverable targets at ${STORE_IP}:"
lab_ssh "$PVE1_IP" "pvesm scan iscsi ${STORE_IP}" || true
lab_ssh "$PVE1_IP" "pvesm add iscsi lab-iscsi --portal ${STORE_IP} --target ${ISCSI_IQN} --content none"
fi
echo "==> Locating the iSCSI block device on pve1"
DEV=""
for i in $(seq 1 24); do
DEV=$(lab_ssh "$PVE1_IP" "for d in /dev/disk/by-path/*iscsi*-lun-1; do [ -e \"\$d\" ] && readlink -f \"\$d\"; done 2>/dev/null | head -1")
[[ -n "$DEV" ]] && break
# nudge a session login/rescan
lab_ssh "$PVE1_IP" "iscsiadm -m node -l 2>/dev/null; iscsiadm -m session -R 2>/dev/null" || true
sleep 5
done
[[ -n "$DEV" ]] || { echo "ERROR: iSCSI LUN device did not appear on pve1"; exit 1; }
echo " LUN device: $DEV"
echo "==> Creating shared LVM volume group 'pve_shared' on the LUN (pve1)"
if lab_ssh "$PVE1_IP" "vgs --noheadings -o vg_name 2>/dev/null | grep -qw pve_shared"; then
echo " VG pve_shared already exists"
else
lab_ssh "$PVE1_IP" "pvcreate -ff -y ${DEV} && vgcreate pve_shared ${DEV}"
fi
echo "==> Adding shared LVM storage 'lab-lvm'"
if has_storage lab-lvm; then
echo " already present"
else
lab_ssh "$PVE1_IP" "pvesm add lvm lab-lvm --vgname pve_shared --shared 1 --content images,rootdir"
fi
# make sure pve2 also sees the new VG on the shared LUN
lab_ssh "$PVE2_IP" "iscsiadm -m session -R 2>/dev/null; pvscan --cache 2>/dev/null; vgscan 2>/dev/null" || true
echo "==> Storage status on pve1"
lab_ssh "$PVE1_IP" "pvesm status"
echo
echo "Shared storage configured. Next: ./verify.sh"