All command should be
run with root privileges,.
1. Create empty file:
This file will contain
virtual memory contents so make file big enough for your needs. This
one will create 1Gb file which means +1Gb swap space for your system:
dd if=/dev/zero
of=/media/swapdd/swapfile.img bs=1024 count=1M
If you want to make 3Gb
file then change count value to count=3M. See man dd for more
information.
2. Bake swap file:
Following command is
going to make "swap filesystem" inside your fresh swap
file.
mkswap
/media/swapdd/swapfile.img
3. Bring up on boot:
To make sure that your
new swap space is activated while booting up computer you should add
it to filesystem configuration file /etc/fstab.
/media/swapdd/swapfile.img
swap swap sw 0 0
4. Activate:
You can either reboot
your computer or activate new swap file by hand with following
command:
swapon
/media/swapdd/swapfile.img
You can use following
commands to check your new swap and confirm that it is active:
cat /proc/swaps
Filename
Type Size Used Priority
/media/swapdd/swapfile.img file 8388604 2724 -1
grep 'Swap'
/proc/meminfo
SwapCached:
4772 kB
SwapTotal:
8388604 kB
SwapFree:
8355812 kB