Swap file is used by operating system to increase performance. Below are step by step guides how to create swap file in GNU Linux operating system:
- First of all, we determine the size of the new swap file and multiple it by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.
- After that, at a shell prompt as root, type the following syntax with count is being equal to the desired block size:
dd if=/dev/zero of=/myswapfile bs=1024 count=65536
- And then create the swap file with this syntax:
mkswap /myswapfile
- To enable the swap file immediately, execute this syntax:
swapon /myswapfile
- To enable swap file at boot time, modify /etc/fstab file to include this line:
/myswapfile swap swap defaults 0 0
The next time the system boots, it will automatically enable the new swap file.
- To check the swap file we can use this command:
cat /proc/swaps
or
free
or
swapon -s