Creating ‘Swap’ [‘Virtual’] Memory on Linux/Unix Operating System

Here’s some help for when you have too little RAM/memory and are trying to do memory-intensive steps, like indexing the human genome reference or doing other NGS-related processing.The way to do it is to create a ‘swap file’, as follows:

1) Check disk/drive usages:

df

2) Create the space. This step is long if you select a large amount of space. In this example, 512MB is created under root (/), given that block size (bs) is 1024 bytes:

sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k

3) Switch it on:

sudo mkswap /swapfile

*This will only last until you restart the operating system, so, useful as a temporary measure. To make the swapfile permanent, do the following:

4) Open the following file:

sudo nano /etc/fstab

Paste in the following:

/swapfile    none     swap     sw     0     0

 

Article by: Dr. Kevin Blighe