Why can't I enable swap on startup?

I made I swap partition with GParted and it works great, since my computer only has 2 GB of memory. But, every time I boot up, I have to execute sudo swapon /dev/sda1 until it enables. How can I set it up so it enables automatically. I am have only been using Ubuntu for three months, so you might have to spell things out for me.


Solution 1:

Swap partitions are enabled either:

  • on boot if they're listed in /etc/fstab
  • when you run swapon /dev/<device>
  • or when you run swapon -a, given that you have some swap devices configured in fstab.

Run:

grep swap /etc/fstab

If there's no output, you don't have a swap partition added to /etc/fstab.

If your swap partition is i.e. /dev/sda1 add

/dev/sda1 none swap sw 0 0

to the end of your /etc/fstab file and run swapon -a.

Verify that your partition is in use as a swap via

cat /proc/swaps