Skip to main content

How to Increase Linux Swap Memory by Resizing a Swap File

HardReset.InfoJanuary 2, 20265 min178 views
9 connections·8 entities in this video→

Checking Current Swap

  • πŸ” Check current swap status using free -h or swapon -s to see existing swap file size and location.
  • πŸ’‘ The video demonstrates resizing an existing 2GB swap file to 4GB, assuming one is already created.

Disabling and Removing Existing Swap

  • ⚠️ Turn off the swap file using sudo swapoff /swapfile to disable it.
  • πŸ—‘οΈ Remove the existing swap file with sudo rm /swapfile.
  • πŸ“Œ Ensure you use the correct path for your swap file if it differs from /swapfile.

Creating and Configuring a New Swap File

  • πŸš€ Create a new, larger swap file (e.g., 4GB) using sudo fallocate -l 4G /swapfile.
  • πŸ”’ Set secure permissions for the swap file with sudo chmod 600 /swapfile, ensuring only the administrator has read/write access.
  • πŸ› οΈ Format the new swap file as swap space using sudo mkswap /swapfile.
  • βœ… Activate the new swap file immediately with sudo swapon /swapfile.

Verifying and Making Swap Persistent

  • πŸ“Š Verify the new swap size and status using swapon -s or free -h to confirm it's active and shows the correct size.
  • πŸ”„ Make the swap file persistent across reboots by editing /etc/fstab.
  • πŸ“ Add the line /swapfile none swap sw 0 0 to the end of /etc/fstab to ensure the swap file is mounted automatically after restarting the system.
Knowledge graph8 entities Β· 9 connections

How they connect

An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.

Hover Β· drag to explore
8 entities
Chapters2 moments

Key Moments

Transcript20 segments

Full Transcript

Topics11 themes

What’s Discussed

LinuxSwap MemorySwap FileResize Swap FileTerminal CommandsfstabchmodmkswapswaponfallocateLinux Tips
Smart Objects8 Β· 9 links
ProductsΒ· 7
ConceptΒ· 1