@@ -3211,42 +3211,29 @@ create_lxc_container() {
32113211 fi
32123212 fi
32133213
3214- # Validate content types
3215- msg_info " Validating content types of storage '$CONTAINER_STORAGE '"
3216- STORAGE_CONTENT=$( grep -A4 -E " ^(zfspool|dir|lvmthin|lvm|linstor): $CONTAINER_STORAGE " /etc/pve/storage.cfg | grep content | awk ' {$1=""; print $0}' | xargs)
3217- 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-
3229- grep -qw " rootdir" <<< " $STORAGE_CONTENT" || {
3230- msg_error " Storage '$CONTAINER_STORAGE ' does not support 'rootdir'. Cannot create LXC."
3231- exit 217
3232- }
3233- $STD msg_ok " Storage '$CONTAINER_STORAGE ' supports 'rootdir'"
3214+ msg_info " Validating storage '$CONTAINER_STORAGE '"
3215+ STORAGE_TYPE=$( grep -E " ^[^:]+: $CONTAINER_STORAGE $" /etc/pve/storage.cfg | cut -d: -f1 | head -1)
3216+
3217+ case " $STORAGE_TYPE " in
3218+ iscsidirect) exit 212 ;;
3219+ iscsi | zfs) exit 213 ;;
3220+ cephfs) exit 219 ;;
3221+ pbs) exit 224 ;;
3222+ linstor | rbd | nfs | cifs)
3223+ pvesm status -storage " $CONTAINER_STORAGE " & > /dev/null || exit 217
3224+ ;;
3225+ esac
32343226
3235- msg_info " Validating content types of template storage '$TEMPLATE_STORAGE '"
3236- TEMPLATE_CONTENT=$( grep -A4 -E " ^[^:]+: $TEMPLATE_STORAGE " /etc/pve/storage.cfg | grep content | awk ' {$1=""; print $0}' | xargs)
3237- msg_debug " Template storage '$TEMPLATE_STORAGE ' has content types: $TEMPLATE_CONTENT "
3227+ pvesm status -content rootdir 2> /dev/null | awk ' NR>1{print $1}' | grep -qx " $CONTAINER_STORAGE " || exit 213
3228+ msg_ok " Storage '$CONTAINER_STORAGE ' ($STORAGE_TYPE ) validated"
32383229
3239- # Check if template storage is LINSTOR (may need special handling)
3230+ msg_info " Validating template storage ' $TEMPLATE_STORAGE ' "
32403231 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
32443232
3245- if ! grep -qw " vztmpl" <<< " $TEMPLATE_CONTENT" ; then
3246- msg_warn " Template storage '$TEMPLATE_STORAGE ' does not declare 'vztmpl'. This may cause pct create to fail."
3247- else
3248- $STD msg_ok " Template storage '$TEMPLATE_STORAGE ' supports 'vztmpl'"
3233+ if ! pvesm status -content vztmpl 2> /dev/null | awk ' NR>1{print $1}' | grep -qx " $TEMPLATE_STORAGE " ; then
3234+ msg_warn " Template storage '$TEMPLATE_STORAGE ' may not support 'vztmpl'"
32493235 fi
3236+ msg_ok " Template storage '$TEMPLATE_STORAGE ' validated"
32503237
32513238 # Free space check
32523239 STORAGE_FREE=$( pvesm status | awk -v s=" $CONTAINER_STORAGE " ' $1 == s { print $6 }' )
@@ -3261,7 +3248,7 @@ create_lxc_container() {
32613248 msg_info " Checking cluster quorum"
32623249 if ! pvecm status | awk -F' :' ' /^Quorate/ { exit ($2 ~ /Yes/) ? 0 : 1 }' ; then
32633250 msg_error " Cluster is not quorate. Start all nodes or configure quorum device (QDevice)."
3264- exit 201
3251+ exit 210
32653252 fi
32663253 msg_ok " Cluster is quorate"
32673254 fi
@@ -3298,6 +3285,14 @@ create_lxc_container() {
32983285 ONLINE_TEMPLATE=" "
32993286 [[ ${# ONLINE_TEMPLATES[@]} -gt 0 ]] && ONLINE_TEMPLATE=" ${ONLINE_TEMPLATES[-1]} "
33003287
3288+ if [[ ${# ONLINE_TEMPLATES[@]} -gt 0 ]]; then
3289+ count=0
3290+ for idx in " ${! ONLINE_TEMPLATES[@]} " ; do
3291+ (( count++ ))
3292+ [[ $count -ge 3 ]] && break
3293+ done
3294+ fi
3295+
33013296 if [[ ${# LOCAL_TEMPLATES[@]} -gt 0 ]]; then
33023297 TEMPLATE=" ${LOCAL_TEMPLATES[-1]} "
33033298 TEMPLATE_SOURCE=" local"
@@ -3525,7 +3520,6 @@ create_lxc_container() {
35253520 if [[ " $PCT_OSTYPE " == " debian" ]]; then
35263521 OSVER=" $( parse_template_osver " $TEMPLATE " ) "
35273522 if [[ -n " $OSVER " ]]; then
3528- # Proactive, but without abort – only offer
35293523 offer_lxc_stack_upgrade_and_maybe_retry " no" || true
35303524 fi
35313525 fi
@@ -3554,7 +3548,7 @@ create_lxc_container() {
35543548 }
35553549 flock -w 60 9 || {
35563550 msg_error " Timeout while waiting for template lock."
3557- exit 202
3551+ exit 211
35583552 }
35593553
35603554 LOGFILE=" /tmp/pct_create_${CTID} _$( date +%Y%m%d_%H%M%S) _${SESSION_ID} .log"
@@ -3603,12 +3597,12 @@ create_lxc_container() {
36033597 0) : ;; # success - container created, continue
36043598 2)
36053599 echo " Upgrade was declined. Please update and re-run:
3606- apt update && apt install --only-upgrade pve-container lxc-pve"
3607- exit 213
3600+ apt update && apt install --only-upgrade pve-container lxc-pve"
3601+ exit 231
36083602 ;;
36093603 3)
36103604 echo " Upgrade and/or retry failed. Please inspect: $LOGFILE "
3611- exit 213
3605+ exit 231
36123606 ;;
36133607 esac
36143608 else
@@ -3635,12 +3629,12 @@ create_lxc_container() {
36353629 0) : ;; # success - container created, continue
36363630 2)
36373631 echo " Upgrade was declined. Please update and re-run:
3638- apt update && apt install --only-upgrade pve-container lxc-pve"
3639- exit 213
3632+ apt update && apt install --only-upgrade pve-container lxc-pve"
3633+ exit 231
36403634 ;;
36413635 3)
36423636 echo " Upgrade and/or retry failed. Please inspect: $LOGFILE "
3643- exit 213
3637+ exit 231
36443638 ;;
36453639 esac
36463640 else
0 commit comments