Skip to content

Instantly share code, notes, and snippets.

@gboeer
Created May 8, 2024 09:27
Show Gist options
  • Save gboeer/e73e43c7597a496fe105324da7baa726 to your computer and use it in GitHub Desktop.
Save gboeer/e73e43c7597a496fe105324da7baa726 to your computer and use it in GitHub Desktop.
This script is used to manage swap space on a Linux system. It first disables all swapping, deletes any existing swap file, creates a new swap file with a size of 12000 MB, sets appropriate permissions for security, formats the file as swap space, and finally activates the swap space.
#!/bin/bash
# Disable swapping for all swap devices and files.
sudo swapoff -a
# Remove the swap file.
sudo rm /swapfile
# Create a new swap file with size 12000 MB.
sudo dd if=/dev/zero of=/swapfile bs=1M count=12000
# Set file permissions to restrict access.
sudo chmod 600 /swapfile
# Set up the swap area on the file.
sudo mkswap /swapfile
# Activate all swap devices and files.
sudo swapon -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment