Skip to content

Commit c35102b

Browse files
committed
feat: Improve LXC network checks and LINSTOR storage handling
Enhanced LXC container network setup to check for both IPv4 and IPv6 addresses, added connectivity (ping) tests, and provided troubleshooting tips on failure. Updated storage validation to support LINSTOR, including cluster connectivity checks and special handling for LINSTOR template storage.
1 parent 5dfb248 commit c35102b

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

misc/build.func

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,20 +2629,48 @@ EOF
26292629
if [ "$var_os" != "alpine" ]; then
26302630
msg_info "Waiting for network in LXC container"
26312631

2632-
# Wait for IP
2632+
# Wait for IP assignment (IPv4 or IPv6)
2633+
local ip_in_lxc=""
26332634
for i in {1..20}; do
2634-
ip_in_lxc=$(pct exec "$CTID" -- ip -4 addr show dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
2635+
# Try IPv4 first
2636+
ip_in_lxc=$(pct exec "$CTID" -- ip -4 addr show dev eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1)
2637+
# Fallback to IPv6 if IPv4 not available
2638+
if [ -z "$ip_in_lxc" ]; then
2639+
ip_in_lxc=$(pct exec "$CTID" -- ip -6 addr show dev eth0 scope global 2>/dev/null | awk '/inet6 / {print $2}' | cut -d/ -f1 | head -n1)
2640+
fi
26352641
[ -n "$ip_in_lxc" ] && break
26362642
sleep 1
26372643
done
26382644

26392645
if [ -z "$ip_in_lxc" ]; then
26402646
msg_error "No IP assigned to CT $CTID after 20s"
2647+
echo -e "${YW}Troubleshooting:${CL}"
2648+
echo " • Verify bridge ${BRG} exists and has connectivity"
2649+
echo " • Check if DHCP server is reachable (if using DHCP)"
2650+
echo " • Verify static IP configuration (if using static IP)"
2651+
echo " • Check Proxmox firewall rules"
2652+
echo " • If using Tailscale: Disable MagicDNS temporarily"
26412653
exit 1
26422654
fi
26432655

2644-
# Simple connectivity check - just verify IP is assigned
2645-
msg_ok "Network configured (IP: $ip_in_lxc)"
2656+
# Verify basic connectivity (ping test)
2657+
local ping_success=false
2658+
for retry in {1..3}; do
2659+
if pct exec "$CTID" -- ping -c 1 -W 2 1.1.1.1 &>/dev/null ||
2660+
pct exec "$CTID" -- ping -c 1 -W 2 8.8.8.8 &>/dev/null ||
2661+
pct exec "$CTID" -- ping6 -c 1 -W 2 2606:4700:4700::1111 &>/dev/null; then
2662+
ping_success=true
2663+
break
2664+
fi
2665+
sleep 2
2666+
done
2667+
2668+
if [ "$ping_success" = false ]; then
2669+
msg_warn "Network configured (IP: $ip_in_lxc) but connectivity test failed"
2670+
echo -e "${YW}Container may have limited internet access. Installation will continue...${CL}"
2671+
else
2672+
msg_ok "Network in LXC is reachable (ping)"
2673+
fi
26462674
fi
26472675
# Function to get correct GID inside container
26482676
get_container_gid() {
@@ -3185,8 +3213,19 @@ create_lxc_container() {
31853213

31863214
# Validate content types
31873215
msg_info "Validating content types of storage '$CONTAINER_STORAGE'"
3188-
STORAGE_CONTENT=$(grep -A4 -E "^(zfspool|dir|lvmthin|lvm): $CONTAINER_STORAGE" /etc/pve/storage.cfg | grep content | awk '{$1=""; print $0}' | xargs)
3216+
STORAGE_CONTENT=$(grep -A4 -E "^(zfspool|dir|lvmthin|lvm|linstor): $CONTAINER_STORAGE" /etc/pve/storage.cfg | grep content | awk '{$1=""; print $0}' | xargs)
31893217
msg_debug "Storage '$CONTAINER_STORAGE' has content types: $STORAGE_CONTENT"
3218+
3219+
# Check storage type for special handling
3220+
STORAGE_TYPE=$(grep -E "^[^:]+: $CONTAINER_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1)
3221+
if [[ "$STORAGE_TYPE" == "linstor" ]]; then
3222+
msg_info "Detected LINSTOR storage - verifying cluster connectivity"
3223+
if ! pvesm status -storage "$CONTAINER_STORAGE" &>/dev/null; then
3224+
msg_error "LINSTOR storage '$CONTAINER_STORAGE' not accessible. Check LINSTOR cluster health."
3225+
exit 217
3226+
fi
3227+
fi
3228+
31903229
grep -qw "rootdir" <<<"$STORAGE_CONTENT" || {
31913230
msg_error "Storage '$CONTAINER_STORAGE' does not support 'rootdir'. Cannot create LXC."
31923231
exit 217
@@ -3196,6 +3235,13 @@ create_lxc_container() {
31963235
msg_info "Validating content types of template storage '$TEMPLATE_STORAGE'"
31973236
TEMPLATE_CONTENT=$(grep -A4 -E "^[^:]+: $TEMPLATE_STORAGE" /etc/pve/storage.cfg | grep content | awk '{$1=""; print $0}' | xargs)
31983237
msg_debug "Template storage '$TEMPLATE_STORAGE' has content types: $TEMPLATE_CONTENT"
3238+
3239+
# Check if template storage is LINSTOR (may need special handling)
3240+
TEMPLATE_TYPE=$(grep -E "^[^:]+: $TEMPLATE_STORAGE$" /etc/pve/storage.cfg | cut -d: -f1)
3241+
if [[ "$TEMPLATE_TYPE" == "linstor" ]]; then
3242+
msg_info "Template storage uses LINSTOR - ensuring resource availability"
3243+
fi
3244+
31993245
if ! grep -qw "vztmpl" <<<"$TEMPLATE_CONTENT"; then
32003246
msg_warn "Template storage '$TEMPLATE_STORAGE' does not declare 'vztmpl'. This may cause pct create to fail."
32013247
else

0 commit comments

Comments
 (0)