Showing posts with label Beginner Guide. Show all posts
Showing posts with label Beginner Guide. Show all posts

Friday, February 13, 2026

How to Force Disk Error Checks (fsck) at Every Boot in Kali Linux

Kali Linux Power User Guide - Kali AI Scripts

Kali Linux Power User Guide

Optimizing Swap, RAM, and Virtual Machine Stability for AI and Multi-VM Workloads.

Context: This guide is designed for users with 16GB RAM running heavy workloads (e.g., 6 VirtualBox VMs + Local AI + VS Code). When your total required RAM exceeds your physical RAM, these steps prevent system crashes.

The Power User Option: > How to Run 6+ VMs on Kali Linux Without Crashing: The Ultimate Swap & Stability Guide

The Technical Option: > Kali Linux Memory Management: Resizing Swap and Automating VM Stability for Local AI

The "Hacker" Aesthetic: > Hardening Kali: Optimizing RAM & Swap for High-Performance Virtualization

1. Resizing Swap (Switching to a 16GB Swap File)

Instead of resizing risky disk partitions, we use a Swap File. It is faster to set up and provides identical performance on modern SSDs.

Step A: Create the Swap File

Run these commands in order. We are creating a 16GB file to act as a safety buffer for your 16GB RAM.

# Turn off existing swap
sudo swapoff -a

# Create a 16GB file (This may take a moment)
sudo fallocate -l 16G /swapfile

# Secure the file so only root can read it
sudo chmod 600 /swapfile

# Format the file as Swap
sudo mkswap /swapfile

# Activate the new swap
sudo swapon /swapfile

# Verify the size (Look for 16G under the Swap row)
free -h
Kali Linux Swap configuration

Figure 1: Verified 16GiB Swap configuration in the Kali terminal. (Click to enlarge)

Step B: Make it Permanent

Without this step, the swap will disappear when you reboot. We must tell Linux to load it at every boot.

  1. Open the config file: sudo nano /etc/fstab
  2. Look for any old lines containing the word swap and put a # at the start of that line to disable it.
  3. Add this exact line to the very bottom of the file:
    /swapfile none swap sw 0 0

2. Optimizing "Swappiness"

By default, Linux swaps data quite early. For AI tasks, we want to keep data in the physical RAM as long as possible.

# Apply immediately
sudo sysctl vm.swappiness=10

# Make it permanent
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf

3. Real-Time Monitoring Scripts

A. Create a Per-Process Swap Checker

This shows exactly which VM or AI process is using your swap space.

#!/bin/bash
printf "%-10s %-15s %-10s\n" "PID" "Process" "Swap Used"
echo "------------------------------------------"
for file in /proc/*/status ; do
  awk '/^Name:/ {name=$2} /^Pid:/ {pid=$2} /^VmSwap:/ {swap=$2 " " $3} END {if (swap) printf "%-10s %-15s %-10s\n", pid, name, swap}' "$file" 2>/dev/null
done | sort -k 3 -nr | head -n 15

4. The "Panic Button" for VMs

If the system begins to lag, use this to instantly pause all 6 VMs and freeze their RAM usage.

#!/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 ACTION" "All VirtualBox VMs have been PAUSED."
Final Note: Running 24GB worth of VMs on 16GB of RAM is "Over-provisioning." Your 16GB Swap file makes this possible, but you will still experience disk-speed latency when switching between VMs.

Generated for Kali Linux Power Users - 2026
#Linux #CyberSecurity #VirtualBox #SysAdmin