Integrate Proxmox host optimization into one-button optimizer

Major changes:
- Added Proxmox detection with interactive mode selection
- Mode 1: Proxmox Host (hypervisor-optimized)
  - Different kernel parameters (swappiness=10, BBR, FQ)
  - Minimal tmpfs (2GB APT cache only)
  - No zram (VMs need direct RAM)
  - No desktop app configuration
- Mode 2: Desktop (original behavior with warnings)
- Mode 3: Abort (recommends running in VMs)

Technical implementation:
- check_proxmox() now offers mode selection
- analyze_and_prompt() branches on PROXMOX_MODE
- tune_kernel() handles both desktop and proxmox profiles
- setup_tmpfs() handles minimal proxmox tmpfs
- Updated PROXMOX_COMPATIBILITY.md with new behavior

Result: One unified script for both desktop and Proxmox use cases
This commit is contained in:
mindesbunister
2025-10-06 10:51:40 +02:00
parent 5548f44f17
commit 8683739f21
2 changed files with 289 additions and 65 deletions

View File

@@ -1,14 +1,78 @@
# Proxmox Host Compatibility Analysis # Proxmox Host Compatibility Analysis
## ⚠️ Running on Proxmox Host: Safety Considerations ## ✅ **NEW: Integrated Proxmox Support!**
### 🔴 **NOT RECOMMENDED for Proxmox Host** The one-button optimizer now **automatically detects** Proxmox hosts and offers **two modes**:
This toolkit is designed for **Linux desktop systems** and **should NOT be used on a Proxmox host** without modifications. Here's why: ```bash
sudo ./one-button-optimizer.sh
```
### When run on Proxmox host, you'll see:
```
⚠️ Proxmox VE host detected!
<EFBFBD> System: Proxmox VE (5 VMs, 2 containers)
This tool has TWO modes:
1⃣ Proxmox Host Mode (Hypervisor Optimization)
• Optimized kernel params for VM workloads
• Minimal RAM allocation (2GB for APT cache only)
• CPU performance governor
• Network optimization (BBR, FQ)
• No desktop app configuration
2⃣ Desktop Mode (NOT recommended for host)
• Heavy RAM usage (zram + tmpfs = 40-50%)
• Desktop-focused optimizations
• Will reduce memory available for VMs
3⃣ Abort (Recommended: Run inside your desktop VMs)
Choose mode (1=Proxmox/2=Desktop/3=Abort) [1]:
```
--- ---
## ❌ Potential Issues on Proxmox Host ## 🎯 Proxmox Host Mode Optimizations
When you select **Mode 1 (Proxmox Host Mode)**, you get:
### 1. **Kernel Parameters**
```bash
vm.swappiness = 10 # Allow some swap (not aggressive like desktop)
vm.dirty_ratio = 10 # Handle VM write bursts
vm.dirty_background_ratio = 5 # Start background writes earlier
vm.vfs_cache_pressure = 50 # Balance inode/dentry cache
vm.min_free_kbytes = 67584 # Keep minimum free RAM
# Networking (optimized for VM/CT traffic)
net.core.default_qdisc = fq # Fair Queue
net.ipv4.tcp_congestion_control = bbr # Better bandwidth
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_max_syn_backlog = 8192
```
### 2. **Minimal tmpfs (Optional)**
- Only 2GB for APT package cache
- Minimal RAM impact
- Speeds up `apt upgrade` operations
### 3. **No zram**
- Skipped entirely in Proxmox mode
- VMs need direct RAM access
### 4. **No Desktop Apps**
- Skips browser/IDE configuration
- Focus on hypervisor performance
---
## ❌ What's NOT Safe (Still Applies if You Choose Mode 2)
If you mistakenly choose **Desktop Mode** on Proxmox host:
### 1. **zram Configuration** ### 1. **zram Configuration**
- **Issue**: Creates compressed swap in RAM - **Issue**: Creates compressed swap in RAM

View File

@@ -45,30 +45,65 @@ check_root() {
check_proxmox() { check_proxmox() {
# Detect if running on Proxmox host # Detect if running on Proxmox host
if [[ -f /etc/pve/.version ]] || [[ -d /etc/pve ]] || pveversion &>/dev/null; then if [[ -f /etc/pve/.version ]] || [[ -d /etc/pve ]] || pveversion &>/dev/null; then
IS_PROXMOX_HOST=true
warn "⚠️ Proxmox VE host detected!" warn "⚠️ Proxmox VE host detected!"
echo "" echo ""
echo "This tool is designed for desktop Linux systems and may not be"
echo "suitable for Proxmox hosts. Key concerns:" # Get VM/CT count
local vm_count=$(qm list 2>/dev/null | tail -n +2 | wc -l || echo "0")
local ct_count=$(pct list 2>/dev/null | tail -n +2 | wc -l || echo "0")
echo "🖥️ System: Proxmox VE (${vm_count} VMs, ${ct_count} containers)"
echo "" echo ""
echo " 🔴 zram: Reduces RAM available for VMs" echo "This tool has TWO modes:"
echo " 🟡 tmpfs: Allocates significant memory (up to 40%)"
echo " 🟡 Kernel params: Tuned for desktop, not hypervisor"
echo "" echo ""
echo "📖 See PROXMOX_COMPATIBILITY.md for detailed analysis" echo " 1⃣ Proxmox Host Mode (Hypervisor Optimization)"
echo " • Optimized kernel params for VM workloads"
echo " • Minimal RAM allocation (5-10% max)"
echo " • CPU performance governor"
echo " • ZFS ARC limiting (if applicable)"
echo " • No desktop app configuration"
echo "" echo ""
echo "Recommendations:" echo " 2⃣ Desktop Mode (NOT recommended for host)"
echo " ✅ Run inside desktop VMs (fully safe)" echo " • Heavy RAM usage (zram + tmpfs = 40-50%)"
echo " ⚠️ Run on Proxmox host (may affect VM performance)" echo " • Desktop-focused optimizations"
echo " 📊 Monitoring scripts are always safe" echo " • Will reduce memory available for VMs"
echo "" echo ""
read -p "Continue anyway? (y/N): " -n 1 -r echo " 3⃣ Abort (Recommended: Run inside your desktop VMs)"
echo ""
read -p "Choose mode (1=Proxmox/2=Desktop/3=Abort) [1]: " -n 1 -r
echo echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log "Aborted by user. Consider running inside VMs instead."
exit 0
fi
warn "Proceeding on Proxmox host - monitor VM performance carefully!"
echo "" echo ""
case "$REPLY" in
1|"")
log "Running in Proxmox Host Mode"
PROXMOX_MODE=true
;;
2)
warn "Running in Desktop Mode on Proxmox host - this may affect VMs!"
read -p "Are you sure? This is NOT recommended. (yes/N): " confirm
if [[ "$confirm" != "yes" ]]; then
log "Aborted by user"
exit 0
fi
PROXMOX_MODE=false
warn "Proceeding with desktop optimizations - monitor VM performance!"
echo ""
;;
3|*)
log "Aborted by user. Consider running inside VMs instead."
echo ""
echo "💡 To optimize your desktop VMs:"
echo " 1. SSH into your VM"
echo " 2. Run: sudo ./one-button-optimizer.sh"
echo " 3. Enjoy full desktop optimizations safely!"
exit 0
;;
esac
else
IS_PROXMOX_HOST=false
PROXMOX_MODE=false
fi fi
} }
@@ -83,54 +118,84 @@ analyze_and_prompt() {
echo "📊 System Information:" echo "📊 System Information:"
echo " 💾 RAM: ${ram_gb}GB" echo " 💾 RAM: ${ram_gb}GB"
echo " 🖥️ CPU: ${cpu_cores} cores" echo " 🖥️ CPU: ${cpu_cores} cores"
if [[ "${PROXMOX_MODE:-false}" == "true" ]]; then
echo " 🖥️ Mode: Proxmox Host Optimization"
fi
echo "" echo ""
# Check and prompt for each optimization # Check and prompt for each optimization
local needs_changes=false local needs_changes=false
# === ZRAM CHECK === # === ZRAM CHECK ===
echo "🗜️ zram Compressed Swap Analysis:" if [[ "${PROXMOX_MODE:-false}" == "true" ]]; then
local optimal_size=$((ram_gb / 2)) # Proxmox mode: Skip zram entirely
[[ $optimal_size -lt 2 ]] && optimal_size=2 echo "🗜️ zram Compressed Swap Analysis:"
echo " ⏭️ Skipped (not recommended for Proxmox hosts)"
if [[ -e /dev/zram0 ]] && swapon --show | grep -q zram0; then echo " 💡 Reason: VMs need direct RAM access for performance"
local zram_size=$(swapon --show | grep zram0 | awk '{print $3}') SETUP_ZRAM=false
local zram_gb=$(echo "$zram_size" | sed 's/[^0-9.]//g' | cut -d. -f1) else
# Desktop mode: Original zram logic
echo "🗜️ zram Compressed Swap Analysis:"
local optimal_size=$((ram_gb / 2))
[[ $optimal_size -lt 2 ]] && optimal_size=2
echo " 📈 Current: $zram_size" if [[ -e /dev/zram0 ]] && swapon --show | grep -q zram0; then
echo " 📊 Optimal: ${optimal_size}GB" local zram_size=$(swapon --show | grep zram0 | awk '{print $3}')
local zram_gb=$(echo "$zram_size" | sed 's/[^0-9.]//g' | cut -d. -f1)
if [[ $zram_gb -gt $((optimal_size + 2)) ]] || [[ $zram_gb -lt $((optimal_size - 1)) ]]; then
echo " ⚠️ Current size is suboptimal" echo " 📈 Current: $zram_size"
echo " 📊 Optimal: ${optimal_size}GB"
if [[ $zram_gb -gt $((optimal_size + 2)) ]] || [[ $zram_gb -lt $((optimal_size - 1)) ]]; then
echo " ⚠️ Current size is suboptimal"
needs_changes=true
read -p " Would you like to reconfigure zram to ${optimal_size}GB? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_ZRAM=true
else
SETUP_ZRAM=false
fi
else
echo " ✅ Size is optimal"
SETUP_ZRAM=false
fi
else
echo " ❌ Not configured"
echo " 📊 Recommended: ${optimal_size}GB"
needs_changes=true needs_changes=true
read -p " Would you like to reconfigure zram to ${optimal_size}GB? (y/N): " -n 1 -r read -p " Would you like to configure zram? (y/N): " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_ZRAM=true SETUP_ZRAM=true
else else
SETUP_ZRAM=false SETUP_ZRAM=false
fi fi
else
echo " ✅ Size is optimal"
SETUP_ZRAM=false
fi
else
echo " ❌ Not configured"
echo " 📊 Recommended: ${optimal_size}GB"
needs_changes=true
read -p " Would you like to configure zram? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_ZRAM=true
else
SETUP_ZRAM=false
fi fi
fi fi
echo "" echo ""
# === TMPFS CHECK === # === TMPFS CHECK ===
echo "💾 tmpfs Cache System Analysis:" echo "💾 tmpfs Cache System Analysis:"
local tmpfs_count=$(mount | grep "tmpfs.*tmpfs-cache" | wc -l)
if [[ "${PROXMOX_MODE:-false}" == "true" ]]; then
# Proxmox mode: Minimal tmpfs for APT cache only
echo " 📦 Proxmox Host Mode: Minimal tmpfs allocation"
local apt_cache_size=$(du -sm /var/cache/apt/archives 2>/dev/null | awk '{print $1}' || echo "0")
echo " 📊 Current APT cache: ${apt_cache_size}MB"
echo " 💡 Recommended: 2GB tmpfs for package cache (minimal RAM impact)"
echo ""
read -p " Configure minimal tmpfs for APT cache? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_TMPFS=true
TMPFS_PROFILE="proxmox"
else
SETUP_TMPFS=false
fi
else
# Desktop mode: Original tmpfs logic
local tmpfs_count=$(mount | grep "tmpfs.*tmpfs-cache" | wc -l)
if [[ $tmpfs_count -gt 0 ]]; then if [[ $tmpfs_count -gt 0 ]]; then
echo " ✅ Well configured ($tmpfs_count active mounts)" echo " ✅ Well configured ($tmpfs_count active mounts)"
echo " 📁 Current mounted caches:" echo " 📁 Current mounted caches:"
@@ -372,10 +437,40 @@ analyze_and_prompt() {
SETUP_TMPFS=false SETUP_TMPFS=false
fi fi
fi fi
fi # End desktop mode tmpfs check
echo "" echo ""
# === KERNEL PARAMS CHECK === # === KERNEL PARAMS CHECK ===
echo "⚙️ Kernel Parameters Analysis:" echo "⚙️ Kernel Parameters Analysis:"
if [[ "${PROXMOX_MODE:-false}" == "true" ]]; then
# Proxmox mode: Different kernel parameters
local swappiness=$(sysctl -n vm.swappiness 2>/dev/null || echo "60")
local dirty_ratio=$(sysctl -n vm.dirty_ratio 2>/dev/null || echo "20")
local qdisc=$(sysctl -n net.core.default_qdisc 2>/dev/null || echo "pfifo_fast")
local tcp_congestion=$(sysctl -n net.ipv4.tcp_congestion_control 2>/dev/null || echo "cubic")
echo " 📊 Current: swappiness=$swappiness, dirty_ratio=$dirty_ratio"
echo " 📊 Network: qdisc=$qdisc, tcp_congestion=$tcp_congestion"
echo " 📊 Proxmox Recommended: swappiness=10, dirty_ratio=10, qdisc=fq, tcp_congestion=bbr"
echo ""
if [[ "$swappiness" != "10" ]] || [[ "$dirty_ratio" != "10" ]] || [[ "$qdisc" != "fq" ]]; then
echo " ⚠️ Parameters could be optimized for Proxmox workload"
read -p " Apply Proxmox-optimized kernel parameters? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
TUNE_KERNEL=true
KERNEL_PROFILE="proxmox"
else
TUNE_KERNEL=false
fi
else
echo " ✅ Parameters are optimal for Proxmox"
TUNE_KERNEL=false
fi
else
# Desktop mode: Original kernel parameter logic
if [[ -f /etc/sysctl.d/99-system-optimization.conf ]]; then if [[ -f /etc/sysctl.d/99-system-optimization.conf ]]; then
local swappiness=$(sysctl -n vm.swappiness 2>/dev/null) local swappiness=$(sysctl -n vm.swappiness 2>/dev/null)
local dirty_ratio=$(sysctl -n vm.dirty_ratio 2>/dev/null) local dirty_ratio=$(sysctl -n vm.dirty_ratio 2>/dev/null)
@@ -399,13 +494,14 @@ analyze_and_prompt() {
read -p " Would you like to optimize kernel parameters? (y/N): " -n 1 -r read -p " Would you like to optimize kernel parameters? (y/N): " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_KERNEL=true TUNE_KERNEL=true
KERNEL_PROFILE="desktop"
else else
SETUP_KERNEL=false TUNE_KERNEL=false
fi fi
else else
echo " ✅ Parameters are optimal" echo " ✅ Parameters are optimal"
SETUP_KERNEL=false TUNE_KERNEL=false
fi fi
else else
echo " ❌ Not optimized" echo " ❌ Not optimized"
@@ -413,11 +509,13 @@ analyze_and_prompt() {
read -p " Would you like to optimize kernel parameters? (y/N): " -n 1 -r read -p " Would you like to optimize kernel parameters? (y/N): " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_KERNEL=true TUNE_KERNEL=true
KERNEL_PROFILE="desktop"
else else
SETUP_KERNEL=false TUNE_KERNEL=false
fi fi
fi fi
fi # End desktop mode kernel check
echo "" echo ""
# === SERVICE CHECK === # === SERVICE CHECK ===
@@ -817,6 +915,32 @@ setup_tmpfs() {
log "Setting up tmpfs cache optimization..." log "Setting up tmpfs cache optimization..."
# Check if Proxmox mode
if [[ "${TMPFS_PROFILE:-}" == "proxmox" ]]; then
# Proxmox minimal tmpfs: only for APT cache
mkdir -p /tmp/tmpfs-cache/apt
# Remove existing mount if it exists
if mount | grep -q "/tmp/tmpfs-cache/apt"; then
umount "/tmp/tmpfs-cache/apt" 2>/dev/null || true
fi
mount -t tmpfs -o size=2G tmpfs /tmp/tmpfs-cache/apt
# Configure APT to use tmpfs
mkdir -p /etc/apt/apt.conf.d
echo 'Dir::Cache::Archives "/tmp/tmpfs-cache/apt";' > /etc/apt/apt.conf.d/00tmpfs-cache
# Add to fstab for persistence
if ! grep -q "/tmp/tmpfs-cache/apt" /etc/fstab; then
echo "tmpfs /tmp/tmpfs-cache/apt tmpfs size=2G,mode=0755 0 0" >> /etc/fstab
fi
success "Proxmox minimal tmpfs configured (2GB for APT cache)"
return 0
fi
# Desktop mode: Full tmpfs setup
# Determine profile based on RAM # Determine profile based on RAM
local profile="medium" local profile="medium"
if [[ $SYSTEM_RAM_GB -ge 16 ]]; then if [[ $SYSTEM_RAM_GB -ge 16 ]]; then
@@ -1114,7 +1238,7 @@ PIPEOF
} }
tune_kernel() { tune_kernel() {
if [[ $SETUP_KERNEL != true ]]; then if [[ ${TUNE_KERNEL:-false} != true ]]; then
return 0 return 0
fi fi
@@ -1122,23 +1246,58 @@ tune_kernel() {
local sysctl_conf="/etc/sysctl.d/99-system-optimization.conf" local sysctl_conf="/etc/sysctl.d/99-system-optimization.conf"
# Determine optimal values # Determine optimal values based on mode
local swappiness=5 local swappiness=5
local dirty_ratio=5 local dirty_ratio=5
local profile="desktop" local profile="desktop"
if [[ $SYSTEM_RAM_GB -ge 16 ]]; then if [[ "${KERNEL_PROFILE:-desktop}" == "proxmox" ]]; then
swappiness=1 # Proxmox-specific parameters
dirty_ratio=3
profile="high-memory"
elif [[ $SYSTEM_RAM_GB -le 4 ]]; then
swappiness=10 swappiness=10
dirty_ratio=10 dirty_ratio=10
profile="low-memory" profile="proxmox-host"
fi
cat > "$sysctl_conf" << EOF
cat > "$sysctl_conf" << EOF # Proxmox Host Optimization - Generated $(date)
# System Optimization - Generated $(date) # Profile: $profile for ${SYSTEM_RAM_GB}GB RAM
# Memory management (for hypervisor workload)
vm.swappiness = $swappiness
vm.dirty_ratio = $dirty_ratio
vm.dirty_background_ratio = 5
vm.vfs_cache_pressure = 50
vm.min_free_kbytes = 67584
# Networking (for VM/CT traffic)
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_max_syn_backlog = 8192
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
# File system
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288
# Kernel
kernel.panic = 10
kernel.panic_on_oops = 1
EOF
else
# Desktop-specific parameters
if [[ $SYSTEM_RAM_GB -ge 16 ]]; then
swappiness=1
dirty_ratio=3
profile="high-memory-desktop"
elif [[ $SYSTEM_RAM_GB -le 4 ]]; then
swappiness=10
dirty_ratio=10
profile="low-memory-desktop"
fi
cat > "$sysctl_conf" << EOF
# Desktop System Optimization - Generated $(date)
# Profile: $profile for ${SYSTEM_RAM_GB}GB RAM # Profile: $profile for ${SYSTEM_RAM_GB}GB RAM
# Memory management # Memory management
@@ -1154,6 +1313,7 @@ net.core.wmem_max = 16777216
# General performance # General performance
kernel.sched_autogroup_enabled = 1 kernel.sched_autogroup_enabled = 1
EOF EOF
fi
# Apply immediately # Apply immediately
sysctl -p "$sysctl_conf" sysctl -p "$sysctl_conf"