diff --git a/PROXMOX_COMPATIBILITY.md b/PROXMOX_COMPATIBILITY.md index 5a96143..4ee83f6 100644 --- a/PROXMOX_COMPATIBILITY.md +++ b/PROXMOX_COMPATIBILITY.md @@ -1,14 +1,78 @@ # 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! + +�️ 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** - **Issue**: Creates compressed swap in RAM diff --git a/one-button-optimizer.sh b/one-button-optimizer.sh index 637cbbe..e75b033 100755 --- a/one-button-optimizer.sh +++ b/one-button-optimizer.sh @@ -45,30 +45,65 @@ check_root() { check_proxmox() { # Detect if running on Proxmox host if [[ -f /etc/pve/.version ]] || [[ -d /etc/pve ]] || pveversion &>/dev/null; then + IS_PROXMOX_HOST=true warn "⚠️ Proxmox VE host detected!" 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 " 🔴 zram: Reduces RAM available for VMs" - echo " 🟡 tmpfs: Allocates significant memory (up to 40%)" - echo " 🟡 Kernel params: Tuned for desktop, not hypervisor" + echo "This tool has TWO modes:" 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 "Recommendations:" - echo " ✅ Run inside desktop VMs (fully safe)" - echo " ⚠️ Run on Proxmox host (may affect VM performance)" - echo " 📊 Monitoring scripts are always safe" + echo " 2️⃣ Desktop Mode (NOT recommended for host)" + echo " • Heavy RAM usage (zram + tmpfs = 40-50%)" + echo " • Desktop-focused optimizations" + echo " • Will reduce memory available for VMs" 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 - 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 "" + + 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 } @@ -83,54 +118,84 @@ analyze_and_prompt() { echo "📊 System Information:" echo " 💾 RAM: ${ram_gb}GB" echo " 🖥️ CPU: ${cpu_cores} cores" + if [[ "${PROXMOX_MODE:-false}" == "true" ]]; then + echo " 🖥️ Mode: Proxmox Host Optimization" + fi echo "" # Check and prompt for each optimization local needs_changes=false # === ZRAM CHECK === - echo "🗜️ zram Compressed Swap Analysis:" - local optimal_size=$((ram_gb / 2)) - [[ $optimal_size -lt 2 ]] && optimal_size=2 - - if [[ -e /dev/zram0 ]] && swapon --show | grep -q zram0; then - 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 [[ "${PROXMOX_MODE:-false}" == "true" ]]; then + # Proxmox mode: Skip zram entirely + echo "🗜️ zram Compressed Swap Analysis:" + echo " ⏭️ Skipped (not recommended for Proxmox hosts)" + echo " 💡 Reason: VMs need direct RAM access for performance" + SETUP_ZRAM=false + 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" - echo " 📊 Optimal: ${optimal_size}GB" - - if [[ $zram_gb -gt $((optimal_size + 2)) ]] || [[ $zram_gb -lt $((optimal_size - 1)) ]]; then - echo " ⚠️ Current size is suboptimal" + if [[ -e /dev/zram0 ]] && swapon --show | grep -q zram0; then + local zram_size=$(swapon --show | grep zram0 | awk '{print $3}') + local zram_gb=$(echo "$zram_size" | sed 's/[^0-9.]//g' | cut -d. -f1) + + 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 - 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 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 - 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 echo "" # === TMPFS CHECK === 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 echo " ✅ Well configured ($tmpfs_count active mounts)" echo " 📁 Current mounted caches:" @@ -372,10 +437,40 @@ analyze_and_prompt() { SETUP_TMPFS=false fi fi + fi # End desktop mode tmpfs check echo "" # === KERNEL PARAMS CHECK === 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 local swappiness=$(sysctl -n vm.swappiness 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 echo if [[ $REPLY =~ ^[Yy]$ ]]; then - SETUP_KERNEL=true + TUNE_KERNEL=true + KERNEL_PROFILE="desktop" else - SETUP_KERNEL=false + TUNE_KERNEL=false fi else echo " ✅ Parameters are optimal" - SETUP_KERNEL=false + TUNE_KERNEL=false fi else echo " ❌ Not optimized" @@ -413,11 +509,13 @@ analyze_and_prompt() { read -p " Would you like to optimize kernel parameters? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then - SETUP_KERNEL=true + TUNE_KERNEL=true + KERNEL_PROFILE="desktop" else - SETUP_KERNEL=false + TUNE_KERNEL=false fi fi + fi # End desktop mode kernel check echo "" # === SERVICE CHECK === @@ -817,6 +915,32 @@ setup_tmpfs() { 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 local profile="medium" if [[ $SYSTEM_RAM_GB -ge 16 ]]; then @@ -1114,7 +1238,7 @@ PIPEOF } tune_kernel() { - if [[ $SETUP_KERNEL != true ]]; then + if [[ ${TUNE_KERNEL:-false} != true ]]; then return 0 fi @@ -1122,23 +1246,58 @@ tune_kernel() { local sysctl_conf="/etc/sysctl.d/99-system-optimization.conf" - # Determine optimal values + # Determine optimal values based on mode local swappiness=5 local dirty_ratio=5 local profile="desktop" - if [[ $SYSTEM_RAM_GB -ge 16 ]]; then - swappiness=1 - dirty_ratio=3 - profile="high-memory" - elif [[ $SYSTEM_RAM_GB -le 4 ]]; then + if [[ "${KERNEL_PROFILE:-desktop}" == "proxmox" ]]; then + # Proxmox-specific parameters swappiness=10 dirty_ratio=10 - profile="low-memory" - fi - - cat > "$sysctl_conf" << EOF -# System Optimization - Generated $(date) + profile="proxmox-host" + + cat > "$sysctl_conf" << EOF +# Proxmox Host 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 # Memory management @@ -1154,6 +1313,7 @@ net.core.wmem_max = 16777216 # General performance kernel.sched_autogroup_enabled = 1 EOF + fi # Apply immediately sysctl -p "$sysctl_conf"