Since OpenMandriva Lx 4.3, the installer, Calamares, now proposes to create either a swap partition with or without hibernation or a swap file.
But for some reason (eg you forgot, you upgraded from a previous release with no swap…) you may be in a situation where you have no swap after OpenMandriva Lx is installed.
If any doubt, you can check if you have swap with
In this topic we will manually create a swap file after installation.
Which swap file size
Note that swap file is recommended for stability, but is not very good in term of performance. For best performance, you should rather use a zRAM swap and keep a traditional (file or partition) swap for hibernation and hybrid sleep.
According to the Fedora rawhide documentation, here is the recommended swap size depending on available RAM
|Amount of RAM in the system||Recommended swap space||Recommended swap space if allowing for hibernation|
|less than 2 GB||2 times the amount of RAM||3 times the amount of RAM|
|2 GB - 8 GB||Equal to the amount of RAM||2 times the amount of RAM|
|8 GB - 64 GB||0.5 times the amount of RAM||1.5 times the amount of RAM|
|more than 64 GB||workload dependent||hibernation not recommended|
If any doubt, get your RAM amount by using the command
free -h --si (total column) to have a correspondance with the above table. For instance 7,8 GB, we will use the second row, third column as we want also hibernation.
Then get the RAM size in bytes with the same command without parameters (ie
free). In our example 8025760. Still following our example we multiply per 2 for having the swap file size: 16051520.
Swap file creation
- Open Konsole or another terminal, type the following command with
countbeing equal to the desired swap file size:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=16051520 status=progress
It will take some time. When it’s done change swapfile permissions so that only root can access it
sudo chmod 600 /swapfile
- Setup the swap file:
sudo mkswap /swapfile`
Enable swap (now and for every next boot)
- To enable the swap file immediately but not automatically at boot time:
sudo swapon /swapfile
- To enable it at boot time, edit
and include the following entry
/swapfile swap swap defaults 0 0
Check swap file is active
sudo swapon -s
You should see something like
Filename Type Size Used Priority /swapfile file 16051516 0 -2