When you think about your system, what comes to your mind is RAM. If RAM gets full, what happens? Then let’s learn about Swapfile in Linux Mint. Do you know what Swapfile is, what it is like to use, or what it can do for your system storage? whether you are a beginner or an advanced user, in this guide you can understand about the swapfile that helps to manage your system resources
What is a swap file?
A swap file is a file on your drive that works most like your extra memory when your RAM is full. It helps your computer run smoothly by creating or moving space, such as freeing up RAM for storage. Although a swap file is slower than real RAM.
Why Is Swap Important?
- Prevents System Crashes: If your RAM runs out, swap ensures your applications.
- Supports Heavy Applications: Useful for video editing, large spreadsheets, programming IDEs, or gaming.
- Hibernation: Some Linux setups require swap for saving the system during hibernation.
Step-by-step guide for swap file in Linux Mint
Let’s start with creating a swapfile, increasing its size, and removing the existing file.
Let’s have a quick checklist: you need “sudo” root to access and check that your disk has enough space with the command “df.”
For example, let’s create a 4 GiB swap file on your disk.
Step 1:
Check your swap file/partition if you have an active file on your disk.
By using the command “swapon,” open the terminal in Linux Mint.
you also need to check memory and swap usage by,
“free,” click “Enter.”
Then, by using the command “df,” check the storage on your disk.
Step 2:
Create a swapfile of a size such as 4 GB or 8 GB, which you can prefer based on the space of the disk. , use fallocate if is not available; you can use dd
- With fallocate if available, it can be fast
“sudo fallocate -l 4G /swapfile”
- With dd, it is safe for all file systems.
“sudo dd if=/dev/zero of=/swapfile bs=1M count=4096”
For a 4 GiB = 4*1024 = 4096 MiB, use this count with bs=1M.
Step 3:
To secure the file permission use the command
“sudo chmod 600 /swapfile”
“chmod” is file permission for the users, group, and others, where the digit “6” represents the read & write and “0” represents no permission.
Step 4:
Then format the swap file in your disk, by the command
“sudo mkswap /swapfile” click Enter
You can see the version, Gib, and bytes of the swap file.
Step 5:
Make the file permanent even if you reboot the disk.
by using “echo ‘/swap file none swap sw 0 0’ | sudo tee -a /etc/fstab”
“echo” is simply printing the same command.
“/etc/fstab” is a file system table that represents the partition or swapfile on your device.
Step 6:
Verify that you have created a swap file.
by using the command
- “swapon”
- “free”
- “cat /proc/swaps”
These commands show the file created in the disks and the storage of the file.
Step 7:
Let’s increase an existing swap file that is 4 GB to 8 GB. If swapon shows the swap file, let’s follow this.
check the current swap file is turned off by the command,
“sudo swapoff /swapfile” disables the file.
Step 8:
By running the command “sudo rm /swapfile”
It removes the old file permanently; after that, the old file no longer exists. but the system has less swap until you create a new file.
Step 9:
Using the previous steps of creating a file, the commands proceed by increasing the size to 8GB.
With fallocate (if it is available)
- “sudo fallocate -l 8G /swapfile”
With dd
- “sudo dd if=/dev/zero of=/swapfile bs=1M count=8192”
As the size of the file increases to 8 GB, the count is also increased to 8192
- “sudo chmod 600 /swapfile”
- “echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab”
Step 10:
check the file that has change the size.
By the command “swapon” and clicking enter and “free,” you can see the swap file size.
if you want to remove the existing file, you can use
- “sudo swapoff -v /swapfile”
- “sudo rm /swapfile”
It turns off and removes the existing file from your disk.
Step 11:
if the command exits
“/swapfile none swap sw 0 0” If the file shows, delete it.
click ctrl + O to save it and click Enter
Ctrl + X—save the file.
Step 12:
Then verify using the command; it shows the file is completely removed from the disk.
- “swapon”
- “free”
Ready to boost your Linux Mint performance?
Create or resize your swap file today and give your system the extra memory it needs. Follow the steps above step by step without worrying about slowdowns.
FAQ (Frequently Answered Questions)
1. How much swap do I need?
4GB RAM → 4GB swap is fine.
8GB RAM → 4–8GB swap is sufficient.
2. Can I delete a swap file?
Yes, first turn it off using the command
“sudo swapoff /swapfile”
“sudo rm /swapfile”
3. What’s the difference between swap partition and swap file?
Swap partition is the dedicated disk partition. The swap file is the flexible file on your existing file system. Both serve the same purpose.
4. Can I have multiple swap files?
Yes, you can create multiple swap files if needed:
5. Does swap slow down my computer?
Using swap is slower than RAM because it’s on disk. Swap prevents crashes, but relying on it heavily can reduce performance. It’s best to have enough RAM and use swap as a safety net.
6. Can I use swap file for hibernation?
Yes, but the swap size must be at least equal to RAM, and the system writes RAM contents to swap.
7. How to prioritize swap files?
Linux can use multiple swap areas with different priorities.
8. Will deleting swap harm my system?
Only if your system runs out of RAM. Without swap, memory-intensive apps may crash. Safe to remove if you have plenty of RAM and monitor usage.
Stay updated—follow us for more tips at rootlearning.in.
Discover more from Root Learning
Subscribe to get the latest posts sent to your email.