From 548dc1d0d344c4a3f4c832b4684c2e1a71144422 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Tue, 23 Sep 2025 12:35:45 +0200 Subject: [PATCH] Remove overlay filesystem functionality and add detection/removal capability - Remove unused overlay filesystem configuration and references - Remove overlayfs sections from all profile JSON files - Remove OVERLAY_ENABLED/OVERLAY_PROTECT_CONFIGS from config - Update documentation to focus on tmpfs optimization - Add overlay detection and removal functionality for cleanup - Add remove_overlays() function with safe unmounting - Add overlay status reporting in final optimization summary - Add test-overlay-detection.sh for testing detection logic - Simplify codebase by removing complex unused features - Focus on proven desktop optimizations (tmpfs, zram, kernel) --- CHANGELOG.md | 21 +++++++ README.md | 4 +- TMPFS_FIX_SUMMARY.md | 6 +- configs/default.conf | 2 - demo-tmpfs-scan.sh | 6 +- one-button-optimizer.sh | 91 +++++++++++++++++++++++++++++- profiles/desktop.json | 4 -- profiles/development.json | 8 --- profiles/gaming.json | 3 - test-overlay-detection.sh | 113 ++++++++++++++++++++++++++++++++++++++ test-tmpfs-detection.sh | 4 +- 11 files changed, 233 insertions(+), 29 deletions(-) create mode 100755 test-overlay-detection.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 0619c44..a92f71a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## [2025-09-23] - Overlay Filesystem Removal + +### Removed +- **Overlay filesystem functionality**: Removed unused overlay filesystem features + - Removed `OVERLAY_ENABLED` and `OVERLAY_PROTECT_CONFIGS` from configuration + - Removed `overlayfs` sections from all profile JSON files + - Removed overlay references from documentation and scripts + - Added overlay detection and removal functionality for existing mounts + +### Added +- **Overlay cleanup functionality**: Added ability to detect and remove overlay mounts + - `remove_overlays()` function to safely unmount overlay filesystems + - Automatic cleanup of overlay work/upper directories + - Removal of overlay entries from /etc/fstab + - User prompt when overlay mounts are detected + +### Rationale +- Overlay filesystems are complex and rarely needed on desktop systems +- Most users benefit more from tmpfs cache optimization than overlay complexity +- Simplified codebase by removing unused/incomplete functionality + ## [2025-09-23] - tmpfs Setup Fix ### Fixed diff --git a/README.md b/README.md index 0e53d4d..909e319 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 🚀 **Intelligent system optimization toolkit for Linux desktop systems** -This repository provides automated system tuning based on hardware detection, usage patterns, and best practices for tmpfs, overlay filesystems, and kernel parameter optimization. +This repository provides automated system tuning based on hardware detection, usage patterns, and best practices for tmpfs and kernel parameter optimization. ## ✨ **NEW: One-Button Optimizer** @@ -71,7 +71,7 @@ sudo ./tune-system.sh --auto ## 📊 Supported Optimizations -- **Memory Management**: zram, tmpfs, overlay filesystems +- **Memory Management**: zram, tmpfs optimization - **Kernel Tuning**: vm parameters, scheduler settings - **Cache Optimization**: Browser, IDE, package manager caches - **I/O Optimization**: Storage and network tuning diff --git a/TMPFS_FIX_SUMMARY.md b/TMPFS_FIX_SUMMARY.md index 7c0a2a0..6cbfc9d 100644 --- a/TMPFS_FIX_SUMMARY.md +++ b/TMPFS_FIX_SUMMARY.md @@ -1,7 +1,7 @@ -# tmpfs/Overlay Functionality Fix Summary +# tmpfs Functionality Fix Summary ## 🐛 Issue Identified -The `one-button-optimizer.sh` script was asking users if they wanted to create tmpfs/overlays, but when they chose "yes", nothing happened because the `setup_tmpfs` function was missing. +The `one-button-optimizer.sh` script was asking users if they wanted to create tmpfs optimizations, but when they chose "yes", nothing happened because the `setup_tmpfs` function was missing. ## ✅ Problems Fixed @@ -128,4 +128,4 @@ With the fix applied, users will see: - **Better system responsiveness** under load - **Automatic scaling** based on available hardware -The tmpfs/overlay functionality now works as intended, providing intelligent, automatic optimization of cache directories with proper detection and sizing based on system capabilities. \ No newline at end of file +The tmpfs functionality now works as intended, providing intelligent, automatic optimization of cache directories with proper detection and sizing based on system capabilities. \ No newline at end of file diff --git a/configs/default.conf b/configs/default.conf index dab3686..2a015c5 100644 --- a/configs/default.conf +++ b/configs/default.conf @@ -24,8 +24,6 @@ CUSTOM_SWAPPINESS="" # Leave empty for profile default CUSTOM_DIRTY_RATIO="" # Leave empty for profile default # Advanced settings -OVERLAY_ENABLED=false # Enable overlay filesystems -OVERLAY_PROTECT_CONFIGS=false # Protect system configs with overlay SYSTEMD_SERVICE=true # Install systemd service # Exclusions (space-separated paths) diff --git a/demo-tmpfs-scan.sh b/demo-tmpfs-scan.sh index 52d2cb9..21c5e2b 100755 --- a/demo-tmpfs-scan.sh +++ b/demo-tmpfs-scan.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Demonstration script showing tmpfs/overlay detection and setup +# Demonstration script showing tmpfs detection and setup # This script shows what would happen on a fresh system set -euo pipefail @@ -27,7 +27,7 @@ error() { echo -e "${RED}[WOULD DO]${NC} $1" } -echo "🔍 tmpfs/Overlay Detection and Setup Demonstration" +echo "🔍 tmpfs Detection and Setup Demonstration" echo "==================================================" echo "" @@ -117,7 +117,7 @@ simulate_fresh_system_scan() { size=$(du -sh "$node_dir" 2>/dev/null | cut -f1) project_path=$(dirname "$node_dir") warn " Found: $project_path ($size)" - error " → Could create overlay mount for faster access" + error " → Could cache in tmpfs for faster access" fi done fi diff --git a/one-button-optimizer.sh b/one-button-optimizer.sh index efba589..52122c3 100755 --- a/one-button-optimizer.sh +++ b/one-button-optimizer.sh @@ -113,6 +113,31 @@ analyze_and_prompt() { echo " 🔍 Scanning system for cache directories..." fi + # === OVERLAY FILESYSTEM CHECK === + echo "🗂️ Overlay Filesystem Analysis:" + local overlay_count=$(mount -t overlay | wc -l) + if [[ $overlay_count -gt 0 ]]; then + echo " ⚠️ Found $overlay_count overlay mounts (deprecated for desktop use)" + echo " 📁 Current overlay mounts:" + mount -t overlay | head -3 | awk '{print " " $3 " (overlay)"}' + [[ $overlay_count -gt 3 ]] && echo " ... and $((overlay_count - 3)) more" + echo "" + echo " 💡 Overlays are complex and rarely needed on desktop systems." + echo " 💡 Consider removing them unless specifically required." + needs_changes=true + read -p " Would you like to remove overlay mounts? (y/N): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + REMOVE_OVERLAYS=true + else + REMOVE_OVERLAYS=false + fi + else + echo " ✅ No overlay mounts found (good - not needed for desktop)" + REMOVE_OVERLAYS=false + fi + echo "" + # Always analyze potential tmpfs candidates (even if already configured) local cache_analysis="" local total_cache_size=0 @@ -225,7 +250,7 @@ analyze_and_prompt() { if [[ -d /var/lib/flatpak ]]; then local flatpak_size=$(du -sm /var/lib/flatpak 2>/dev/null | cut -f1 || echo 0) if [[ $flatpak_size -gt 1000 ]]; then - additional_opportunities="${additional_opportunities} Flatpak apps: ${flatpak_size}MB (consider overlayfs)\n" + additional_opportunities="${additional_opportunities} Flatpak apps: ${flatpak_size}MB (consider tmpfs for .cache)\n" fi fi @@ -535,6 +560,7 @@ analyze_and_prompt() { [[ $SETUP_TMPFS == true ]] && actions+=("tmpfs") [[ $SETUP_KERNEL == true ]] && actions+=("kernel") [[ $SETUP_SERVICE == true ]] && actions+=("service") + [[ $REMOVE_OVERLAYS == true ]] && actions+=("remove-overlays") if [[ ${#actions[@]} -gt 0 ]]; then echo "📋 Selected optimizations: ${actions[*]}" @@ -551,7 +577,7 @@ analyze_and_prompt() { fi # Export variables for the optimization functions - export SETUP_ZRAM SETUP_TMPFS SETUP_KERNEL SETUP_SERVICE + export SETUP_ZRAM SETUP_TMPFS SETUP_KERNEL SETUP_SERVICE REMOVE_OVERLAYS export SYSTEM_RAM_GB=$ram_gb } @@ -612,6 +638,58 @@ setup_zram() { success "zram reconfigured with ${zram_size}GB" } +remove_overlays() { + if [[ $REMOVE_OVERLAYS != true ]]; then + return 0 + fi + + log "Removing overlay filesystem mounts..." + + # Get list of overlay mounts + local overlay_mounts=$(mount -t overlay | awk '{print $3}') + + if [[ -z "$overlay_mounts" ]]; then + log "No overlay mounts found to remove" + return 0 + fi + + # Unmount each overlay + echo "$overlay_mounts" | while read -r mount_point; do + if [[ -n "$mount_point" ]]; then + log " Unmounting overlay: $mount_point" + if umount "$mount_point" 2>/dev/null; then + success " Successfully unmounted: $mount_point" + + # Clean up overlay work directories if they exist in /tmp + local work_dir="/tmp/overlay-work$(basename "$mount_point")" + local upper_dir="/tmp/overlay-upper$(basename "$mount_point")" + + if [[ -d "$work_dir" ]]; then + rm -rf "$work_dir" + log " Cleaned up work directory: $work_dir" + fi + + if [[ -d "$upper_dir" ]]; then + rm -rf "$upper_dir" + log " Cleaned up upper directory: $upper_dir" + fi + else + warn " Failed to unmount: $mount_point (may be in use)" + fi + fi + done + + # Remove any overlay entries from fstab + if [[ -f /etc/fstab ]] && grep -q "overlay" /etc/fstab; then + log "Removing overlay entries from /etc/fstab..." + cp /etc/fstab /etc/fstab.backup.$(date +%s) + grep -v "overlay" /etc/fstab > /etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab + success "Removed overlay entries from /etc/fstab" + fi + + success "Overlay filesystem cleanup completed" +} + setup_tmpfs() { if [[ $SETUP_TMPFS != true ]]; then return 0 @@ -934,6 +1012,14 @@ show_final_status() { echo " 📊 Total tmpfs allocated: ${total_mb}MB" fi + # overlay status + local overlay_count=$(mount -t overlay | wc -l) + if [[ $overlay_count -eq 0 ]]; then + echo " 🗂️ overlays: None (optimal for desktop systems)" + else + echo " ⚠️ overlays: $overlay_count mounts found (consider removal)" + fi + # kernel with current values if [[ -f /etc/sysctl.d/99-system-optimization.conf ]]; then local swappiness=$(sysctl -n vm.swappiness 2>/dev/null) @@ -986,6 +1072,7 @@ main() { analyze_and_prompt # Apply selected optimizations + remove_overlays setup_zram setup_tmpfs tune_kernel diff --git a/profiles/desktop.json b/profiles/desktop.json index a1aaf32..fed44e5 100644 --- a/profiles/desktop.json +++ b/profiles/desktop.json @@ -58,10 +58,6 @@ "net.core.netdev_max_backlog": 5000, "net.core.rmem_max": 16777216, "net.core.wmem_max": 16777216 - }, - "overlayfs": { - "enabled": false, - "protect_configs": false } }, "sizing_rules": { diff --git a/profiles/development.json b/profiles/development.json index 995c39b..3cf1838 100644 --- a/profiles/development.json +++ b/profiles/development.json @@ -58,14 +58,6 @@ "fs.file-max": 2097152, "fs.inotify.max_user_watches": 524288, "kernel.pid_max": 32768 - }, - "overlayfs": { - "enabled": true, - "protect_configs": true, - "overlay_paths": [ - "/home/*/workspace", - "/opt/projects" - ] } }, "development_specific": { diff --git a/profiles/gaming.json b/profiles/gaming.json index 7b9ea9e..a8d0ddf 100644 --- a/profiles/gaming.json +++ b/profiles/gaming.json @@ -48,9 +48,6 @@ "net.core.netdev_max_backlog": 10000, "net.core.rmem_max": 33554432, "net.core.wmem_max": 33554432 - }, - "overlayfs": { - "enabled": false } }, "gaming_specific": { diff --git a/test-overlay-detection.sh b/test-overlay-detection.sh new file mode 100755 index 0000000..2a89656 --- /dev/null +++ b/test-overlay-detection.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# Test script to verify overlay detection and removal functionality +# This script creates a temporary overlay mount and tests detection + +set -euo pipefail + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +log() { + echo -e "${BLUE}[TEST]${NC} $1" +} + +success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +warn() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +echo "🔍 Testing Overlay Detection Functionality" +echo "==========================================" +echo "" + +# Check if running as root (needed for mount operations) +if [[ $EUID -eq 0 ]]; then + warn "Running as root - will test actual mount/unmount operations" + CAN_MOUNT=true +else + log "Running as non-root - will test detection logic only" + CAN_MOUNT=false +fi + +# Test 1: Check current overlay mounts +log "Test 1: Checking for existing overlay mounts..." +overlay_count=$(mount -t overlay 2>/dev/null | wc -l) +if [[ $overlay_count -eq 0 ]]; then + success "No existing overlay mounts found (expected for desktop systems)" +else + warn "Found $overlay_count existing overlay mounts:" + mount -t overlay | awk '{print " " $3}' +fi +echo "" + +# Test 2: Test detection function (simulated) +log "Test 2: Testing overlay detection logic..." +cat << 'EOF' +# This is what the detection code does: +overlay_count=$(mount -t overlay | wc -l) +if [[ $overlay_count -gt 0 ]]; then + echo "Found $overlay_count overlay mounts" + mount -t overlay | awk '{print " " $3 " (overlay)"}' +else + echo "No overlay mounts found" +fi +EOF + +echo "" +log "Running detection logic:" +if [[ $overlay_count -gt 0 ]]; then + echo " ⚠️ Found $overlay_count overlay mounts (would suggest removal)" + mount -t overlay | head -3 | awk '{print " " $3 " (overlay)"}' +else + echo " ✅ No overlay mounts found (good - not needed for desktop)" +fi +echo "" + +# Test 3: Test temporary overlay creation (if root) +if [[ $CAN_MOUNT == true ]]; then + log "Test 3: Creating temporary overlay for testing..." + + # Create temporary directories + mkdir -p /tmp/overlay-test/{lower,upper,work,merged} + echo "test content" > /tmp/overlay-test/lower/testfile.txt + + # Create overlay mount + if mount -t overlay overlay -o lowerdir=/tmp/overlay-test/lower,upperdir=/tmp/overlay-test/upper,workdir=/tmp/overlay-test/work /tmp/overlay-test/merged 2>/dev/null; then + success "Created test overlay mount at /tmp/overlay-test/merged" + + # Test detection again + new_overlay_count=$(mount -t overlay | wc -l) + log "Detection now shows: $new_overlay_count overlay mounts" + + # Clean up + log "Cleaning up test overlay..." + umount /tmp/overlay-test/merged 2>/dev/null || true + rm -rf /tmp/overlay-test + success "Test overlay cleaned up" + else + error "Failed to create test overlay (this is normal on some systems)" + rm -rf /tmp/overlay-test + fi +else + log "Test 3: Skipped (requires root privileges)" +fi + +echo "" +success "Overlay detection test completed!" +echo "" +log "Summary:" +echo " • Overlay detection logic works correctly" +echo " • Current system has $overlay_count overlay mounts" +echo " • Desktop systems typically don't need overlay filesystems" +echo " • The optimizer will offer to remove any found overlays" diff --git a/test-tmpfs-detection.sh b/test-tmpfs-detection.sh index 6ae4c14..be05b61 100755 --- a/test-tmpfs-detection.sh +++ b/test-tmpfs-detection.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Test script to verify tmpfs/overlay detection functionality +# Test script to verify tmpfs detection functionality # This script can be run without root to test the detection logic set -euo pipefail @@ -22,7 +22,7 @@ warn() { echo -e "${YELLOW}[INFO]${NC} $1" } -echo "🔍 Testing tmpfs/overlay Detection Functionality" +echo "🔍 Testing tmpfs Detection Functionality" echo "==============================================" echo ""