Debian

Enabling swap on debian based system

Recently I found myself without a swap partition (having installed another OS and reworked my disk-setup) so I wanted to share a quick guide to enable swap again.

As a recap "swap" space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM.

You can check to see if you have swap partitions defined by consulting /etc/fstab: $ grep swap /etc/fstab UUID=14a0f7b9-dabb-4296-b0e7-013527a7d82d none swap sw 0 0

If one is defined you can check that it is being used by the system:

 $ swapon -s Filename Type Size Used Priority /dev/sda6 partition 1004020 215532 -1 

If one is defined but not in use the obvious thing to do is check that it is formatted as a swap partition:

 $ sudo fdisk -l /dev/sda [..snipped..] /dev/sda5 3842 6595 22121473+ 83 Linux /dev/sda6 6596 6720 1004031 82 Linux swap / Solaris 

If it is a swap partition, ready it for use and turn it on. At this point, you might see any errors that prevented its use.

 su - mkswap /dev/sda6 swapon /dev/sda6 

You can now check that the partition is being used using the "swapon -s" command we saw above.

Add an entry to /etc/fstab to have this swap partition loaded at bootup. You can replace the "UUID=xxx" part from above with "/dev/sda6"; so the entry would look like this:

 /dev/sda6 none swap sw 0 0 

If you didn't define a swap partition earlier, then you'd have to create one, or point swap to a regular file (which is a little less efficient, but probably sufficient).

Original Post

Leave a Reply

Your email address will not be published. Required fields are marked *