Skip to content

Commit 0f7c201

Browse files
authored
core: extend storage type support (rbd, nfs, cifs) and validation (iscidirect, isci, zfs, cephfs, pbs) (#9646)
* core: enhance storage type validation and error codes Improve storage validation for LXC container creation with explicit checks for unsupported storage types. Changes: - Add validation for storage types that don't support containers: - iscsidirect (exit 212) - VMs only - iscsi/zfs (exit 213) - no rootdir support - cephfs (exit 219) - use RBD instead - pbs (exit 224) - backups only - Add connectivity check for network storage (linstor, rbd, nfs, cifs) - Simplify storage content validation using pvesm status - Reorganize Proxmox error codes (200-231) for consistency - Update error messages to be more descriptive and actionable This helps users identify storage compatibility issues early before container creation fails with cryptic errors. * Update build.func
1 parent 5780dc1 commit 0f7c201

File tree

2 files changed

+67
-68
lines changed

2 files changed

+67
-68
lines changed

misc/build.func

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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

misc/error_handler.func

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
# * Node.js/npm errors (243-249, 254)
3535
# * Python/pip/uv errors (210-212)
3636
# * PostgreSQL errors (231-234)
37-
# * MySQL/MariaDB errors (260-263)
38-
# * MongoDB errors (251-253)
39-
# * Proxmox custom codes (200-209, 213-223, 225)
37+
# * MySQL/MariaDB errors (241-244)
38+
# * MongoDB errors (251-254)
39+
# * Proxmox custom codes (200-231)
4040
# - Returns description string for given exit code
4141
# ------------------------------------------------------------------------------
4242
explain_exit_code() {
@@ -79,38 +79,43 @@ explain_exit_code() {
7979
234) echo "PostgreSQL: Fatal error in query / syntax" ;;
8080

8181
# --- MySQL / MariaDB ---
82-
260) echo "MySQL/MariaDB: Connection failed (server not running / wrong socket)" ;;
83-
261) echo "MySQL/MariaDB: Authentication failed (bad user/password)" ;;
84-
262) echo "MySQL/MariaDB: Database does not exist" ;;
85-
263) echo "MySQL/MariaDB: Fatal error in query / syntax" ;;
82+
241) echo "MySQL/MariaDB: Connection failed (server not running / wrong socket)" ;;
83+
242) echo "MySQL/MariaDB: Authentication failed (bad user/password)" ;;
84+
243) echo "MySQL/MariaDB: Database does not exist" ;;
85+
244) echo "MySQL/MariaDB: Fatal error in query / syntax" ;;
8686

8787
# --- MongoDB ---
8888
251) echo "MongoDB: Connection failed (server not running)" ;;
8989
252) echo "MongoDB: Authentication failed (bad user/password)" ;;
9090
253) echo "MongoDB: Database not found" ;;
91+
254) echo "MongoDB: Fatal query error" ;;
9192

9293
# --- Proxmox Custom Codes ---
93-
200) echo "Custom: Failed to create lock file" ;;
94-
201) echo "Custom: Cluster not quorate" ;;
95-
202) echo "Custom: Timeout waiting for template lock (concurrent download in progress)" ;;
96-
203) echo "Custom: Missing CTID variable" ;;
97-
204) echo "Custom: Missing PCT_OSTYPE variable" ;;
98-
205) echo "Custom: Invalid CTID (<100)" ;;
99-
206) echo "Custom: CTID already in use (check 'pct list' and /etc/pve/lxc/)" ;;
100-
207) echo "Custom: Password contains unescaped special characters (-, /, \\, *, etc.)" ;;
101-
208) echo "Custom: Invalid configuration (DNS/MAC/Network format error)" ;;
102-
209) echo "Custom: Container creation failed (check logs for pct create output)" ;;
103-
213) echo "Custom: LXC stack upgrade/retry failed (outdated pve-container - check https://github.com/community-scripts/ProxmoxVE/discussions/8126)" ;;
104-
214) echo "Custom: Not enough storage space" ;;
105-
215) echo "Custom: Container created but not listed (ghost state - check /etc/pve/lxc/)" ;;
106-
216) echo "Custom: RootFS entry missing in config (incomplete creation)" ;;
107-
217) echo "Custom: Storage does not support rootdir (check storage capabilities)" ;;
108-
218) echo "Custom: Template file corrupted or incomplete download (size <1MB or invalid archive)" ;;
109-
220) echo "Custom: Unable to resolve template path" ;;
110-
221) echo "Custom: Template file exists but not readable (check file permissions)" ;;
111-
222) echo "Custom: Template download failed after 3 attempts (network/storage issue)" ;;
112-
223) echo "Custom: Template not available after download (storage sync issue)" ;;
113-
225) echo "Custom: No template available for OS/Version (check 'pveam available')" ;;
94+
200) echo "Proxmox: Failed to create lock file" ;;
95+
203) echo "Proxmox: Missing CTID variable" ;;
96+
204) echo "Proxmox: Missing PCT_OSTYPE variable" ;;
97+
205) echo "Proxmox: Invalid CTID (<100)" ;;
98+
206) echo "Proxmox: CTID already in use" ;;
99+
207) echo "Proxmox: Password contains unescaped special characters" ;;
100+
208) echo "Proxmox: Invalid configuration (DNS/MAC/Network format)" ;;
101+
209) echo "Proxmox: Container creation failed" ;;
102+
210) echo "Proxmox: Cluster not quorate" ;;
103+
211) echo "Proxmox: Timeout waiting for template lock" ;;
104+
212) echo "Proxmox: Storage type 'iscsidirect' does not support containers (VMs only)" ;;
105+
213) echo "Proxmox: Storage type does not support 'rootdir' content" ;;
106+
214) echo "Proxmox: Not enough storage space" ;;
107+
215) echo "Proxmox: Container created but not listed (ghost state)" ;;
108+
216) echo "Proxmox: RootFS entry missing in config" ;;
109+
217) echo "Proxmox: Storage not accessible" ;;
110+
219) echo "Proxmox: CephFS does not support containers - use RBD" ;;
111+
224) echo "Proxmox: PBS storage is for backups only" ;;
112+
218) echo "Proxmox: Template file corrupted or incomplete" ;;
113+
220) echo "Proxmox: Unable to resolve template path" ;;
114+
221) echo "Proxmox: Template file not readable" ;;
115+
222) echo "Proxmox: Template download failed" ;;
116+
223) echo "Proxmox: Template not available after download" ;;
117+
225) echo "Proxmox: No template available for OS/Version" ;;
118+
231) echo "Proxmox: LXC stack upgrade failed" ;;
114119

115120
# --- Default ---
116121
*) echo "Unknown error" ;;

0 commit comments

Comments
 (0)