The easiest solution would be to add a swap file. If you are already encrypting your root file system, I would not bother with an encrypted swap file, which is only a little more difficult, but it is slower. The advantage of a swap file is that you can remove it later to regain the disk space. And the disk is already encrypted!
The steps are straightforward. First, make the file. For example, this would make 1GB of new swap:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024k
The of=/swapfile
tells dd
to put the new swap file in /swapfile
. You can call it anything you want. You can add multiple swap files, too. For recent Linux kernels, the speed is the same as a swap partition.
Then, you need to format the swap file as swap space, like so:
sudo mkswap /swapfile
This command will give you some output like:
Setting up swapspace version 1, size = 1048576 KiB
no label, UUID=83352590-ef57-49f5-84c4-7fb847e4e4e0
And that's your new swap file. Finally, you need to activate the swap on your machine using the following command:
sudo swapon /swapfile
Now, sudo swapon -s
should show you both the swap partition and the swap file.
I then recommend adding some security by changing permissions as follows:
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
If all seems good so far, you can add the swap file permanently by adding the the following line to /etc/fstab
using your favorite editor:
/swapfile none swap sw 0 0
You can add multiple swap files, of course. And you can remove the swap file by using sudo swapoff /swapfile
.
Hope this helps.
Best Answer
You can always create a swap file to add more swap space. This is not the same in every aspect as swap partition, but it will be easy and dynamic.
In the following steps, change
/media/fasthdd/swapfile.img
to anything you like. For example, it can be/swap.img
as well./media/fasthdd/swapfile.img
is just an example filename. If you are using this one, then of course there must be a directory/media/fasthdd/
with enough free space for your new swap file.Use any terminal application to run the commands of the following steps. All commands should be run with root privileges. To do this, you can either add
sudo
to the beginning of every command or runsudo bash
before running the commands.Create an empty file:
This file will contain virtual memory contents so make file big enough for your needs. This one will create a 1GiB file, which means +1GiB swap space for your system:
If you want to make a 3GiB file, then change count value to
count=3M
. Seeman dd
for more information.Bake the swap file:
The following command is going to make a "swap filesystem" inside your fresh swap file.
Bring up on boot:
To make sure that your new swap space is activated while booting up computer, you should add it to the filesystem configuration file
/etc/fstab
. Add it to the end of the file. This is recommended because other filesystems (at least one that contains a swap file) must be mounted in read-write mode before we can access any files.Activate:
You can either reboot your computer or activate the new swap file by hand with the following command:
If everything goes well, you should see that more swap space is available for use. You can use the following commands to check your new swap and confirm that it is active: