Ask Your Question

Revision history [back]

I mentioned in one post before that IMHO easiest method is to use swap file instad of swap partition:

First step is to create empty file of desired size (I'll create 1GB one). You can do that by issuing one of the following commands:

sudo fallocate -l 1G /swapfile


sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

After that change permissions on that file:

sudo chmod 600 /swapfile

Make swap:

sudo mkswap /swapfile

And after all that activate it:

sudo swapon /swapfile

If you want your system to mount that swap automatically on boot you should add following entry in your /etc/fstab file:

/swapfile swap swap defaults 0 0

If you want to use physical partition instead of swap file for some reason you can prepare that partition and in /etc/fstab specify full path to that disk. Or you can use UUID=uuidnumber to identify disk which should be mounted as swap. To find out UUID of your partition/disk you can issue blkid /dev/sdXX where /dev/sdXX is path to your drive/partition