Sunday, February 15, 2026

Comprehensive Guide for Swap Management, VM Stability, and Cleanup

Kali Linux Memory Optimization: Complete Log

Kali Linux Optimization Master Log

Comprehensive Guide for Swap Management, VM Stability, and Cleanup

1. The Core Memory Upgrade (Swap File)

To support 6+ VMs and Local AI on 16GB RAM, we replaced a 1GB physical partition with a 16GB Swap File.

# Create and Activate 16GB Swap
sudo swapoff -a
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -h
Verification: free -h should show ~15Gi to 17Gi under the Swap column.

2. Automation & Stability Scripts

A. The Panic Button (Pause All VMs)

Filename: ~/bin/vm_panic.sh

#!/bin/bash
RUNNING_VMS=$(vboxmanage list runningvms | cut -d '"' -f 2)
echo "$RUNNING_VMS" | while read -r VM; do
    vboxmanage controlvm "$VM" pause
done
notify-send -u critical "PANIC" "All VirtualBox VMs PAUSED."

B. The Resume Button (Unpause All)

Filename: ~/bin/vm_resume.sh

#!/bin/bash
PAUSED_VMS=$(vboxmanage list vms | cut -d '"' -f 2 | while read -r VM; do 
    vboxmanage showvminfo "$VM" --machinereadable | grep -q 'VMState="paused"' && echo "$VM"
done)
echo "$PAUSED_VMS" | while read -r VM; do
    vboxmanage controlvm "$VM" resume
done
notify-send "System Restored" "All paused VMs RESUMED."

3. GUI Cleanup: Deleting Ghost Partitions

We deleted the physical 1GB partition (sdb3) and cleaned /etc/fstab to prevent boot delays.

# Cleanup Command
sudo cp /etc/fstab /etc/fstab.bak && sudo sed -i '/sdb3/d' /etc/fstab
sudo systemctl daemon-reload
Warning: Always check cat /etc/fstab after running sed commands to ensure no critical lines were removed.

4. System Health Check

Use this script to verify your setup is still optimal after a reboot.

  1. Create the health check script: nano ~/check_health.sh
  2. Paste the code below and save the file.
  3. Execute with: bash ~/check_health.sh (Do not use python).
#!/bin/bash
# check_health.sh
echo "--- Swap Health Check ---"
SWAP_SIZE=$(free -h | grep Swap | awk '{print $2}')
echo "Active Swap Size: $SWAP_SIZE"
GHOSTS=$(grep "sdb3" /etc/fstab | grep -v "#")
if [ -z "$GHOSTS" ]; then echo "Result: /etc/fstab is CLEAN"; fi
PERMS=$(stat -c "%a" /swapfile)
if [ "$PERMS" == "600" ]; then echo "Result: Permissions are CORRECT"; fi

✔ SYSTEM OPTIMIZED

16GB RAM + 16GB Swap File | 0.03% Disk overhead | VM Stability: High

Generated on Feb 13, 2026 | User: Kali Linux Power User
#KaliLinux #SystemOptimization #CyberSecurity #Automation

No comments:

Post a Comment