Skip to content

Latest commit

 

History

History
65 lines (55 loc) · 1.2 KB

ubuntu-swap-file.md

File metadata and controls

65 lines (55 loc) · 1.2 KB

Ubuntu

Managing Swap File

Guide for creating or modifying swap file in Ubuntu 22.04

Check Current Swap Status

First, check if you have an existing swap file:

sudo swapon --show

Disable Existing Swap (if any)

If you have an existing swap file that you want to modify, disable it:

sudo swapoff /swapfile

Create or Resize Swap File

Choose the desired size (e.g., 8GB) and create/recreate the swap file:

sudo fallocate -l 8G /swapfile

Note: If fallocate fails, you can use dd instead:

sudo dd if=/dev/zero of=/swapfile bs=1M count=8192

Set Permissions

sudo chmod 600 /swapfile

Initialize Swap Area

sudo mkswap /swapfile

Enable Swap

sudo swapon /swapfile

Make Changes Permanent

Edit the fstab file:

sudo nano /etc/fstab

Add or modify the line:

/swapfile swap swap defaults 0 0

Verify Changes

sudo swapon --show
# or
free -m

Apply Changes

Reboot your system to ensure all changes take effect properly:

sudo reboot

Note: The default swap file location is /swapfile. If you want to use a different location, adjust the paths in the commands accordingly.