Advertising

Welcome to SparkyLinux forums
Zapraszamy również na polsko-języczne Forum https://forum.linuxiarze.pl

[Solved] Using Swap File Instead of Swap Partition

Started by duststuff, January 26, 2024, 04:20:51 PM

Previous topic - Next topic

duststuff

The wiki mentions that you need a swap partition to install / run Sparky but my understanding is that you can use a swap file instead if you wish. Following is one method for creating and enabling a swap file on your system. (Each of the commands needs to be run with elevated privileges, represented by 'sudo' in these examples.)

1. Create a file of the desired size in the desired location with the desired name:
sudo fallocate -l 4G /swapfileNotes: 'fallocate' is the program being run. '-l 4G' tells it to create a file with a 'length' (i.e. size) of 4 GB. '/swapfile' tells it to create the file in the root ('/') directory and name it 'swapfile'.

2. Give the file the necessary access permissions:
sudo chmod 0600 /swapfile
3. 'Convert' the file into a swap-type file:
sudo mkswap /swapfileIf you want to confirm this worked, you can run this command:
sudo file /swapfile
4. Enable the file for swap use:
sudo swapon /swapfileAt this point, the system should have access to this file to use as swap space if needed. If you have 'inxi' installed, you can run the following command to confirm this:
inxi --swap
In order for this to be persistent and available for the system on subsequent boots, you need to add the following line to the /etc/fstab file:
/swapfile none swap defaults 0 0
I found this solution via an online comment and it has been working for me. There are probably other ways of accomplishing this same thing. Others can feel free to offer any additional information or advice they think might be helpful in regards to the use of swap files.

View the most recent posts on the forum