Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I did not opt for a swap partition during Ubuntu installation. Later I freed up some space, and made a swap partition. Now after booting up I am manually opening gparted and right-clicking the swap partition and turning it on using 'swapon' option.

How can I automatically enable the swap partition every time?

share|improve this question… – Qasim Mar 13 '14 at 12:04

5 Answers 5

up vote 55 down vote accepted

You need to edit /etc/fstab and add the new swap partition.

sudo nano /etc/fstab

You need to add a line that looks like

UUID=735b3be3-779c-4d21-a944-b033225f3ab4 none   swap    sw      0       0

and you get the UUID using the command

sudo blkid /dev/sda3

(substitute /dev/sda3 with the appropriate device name).


share|improve this answer
Need Help for /etc/fstan i ma getting output :- bash: /etc/fstab: Permission denied – Ashu Aug 31 '14 at 8:20
Use sudo gedit /etc/fstab – Heather Brown Nov 29 '14 at 22:37

To create a swap partition after installation, create an empty partition that should have no holes. You can then format this partition with:

sudo mkswap /dev/sdX

replacing /dex/sdX with your partition. Mount this partition as swap with

sudo swapon -U UUID

where UUID is that of your /dev/sdX as read from this:

blkid /dev/sdX

Bind your new swap in /etc/fstab by adding this line:

UUID=xxx    none    swap    sw      0   0

If you want to use your swap for hibernating then you need to update the UUID in /etc/initramfs-tools/conf.d/resume with this content RESUME=UUID=xxx. Don't forget to $ sudo update-initramfs -u.

To complete things: it would also be possible to create a swap file in case we do not have a spare partition. This answer gives you an idea on how to create such a file and enable it on boot.

share|improve this answer
As of right now, I have a SSD with two partitions, but I would like to make a third one. If I have a primary ext4 partition that holds the OS and my files, can I use this to peel off 2GB off it into t a new partition? This primary partition has more than enough free space so that shouldn't be an issue. – dustin Apr 4 at 22:46

You have to have a swap filesystem defined in /etc/fstab. It should contain a line similar to

UUID=67682d1b-a1d8-4377-a3dd-67340c141619 none            swap    sw              0       0

Of course you need to substitute the value of UUID with the identifier of your device.

share|improve this answer
how can I get it? – user13593 Apr 5 '11 at 20:21
You can use the device name instead, like /dev/sda1 (without the UUID). – Adam Byrtek Apr 5 '11 at 20:30

from just create swap file as that is more flexible and you can dynamically adjust how many and how large swap storages you have. That also allows you to move swap partition away from your system disk, thus making system faster. Also, if you use several swap spaces, adjust their priority of use to same value, so round-robin is used to write in them, allowing you to get even more speed improvements.

p.s. i would use UUID instead of device name, because it is easily possible to change device order if by accident you leave USB storage inside USB slot and simply removing and plugging back sata cables - you do not need to worry much about what drive is connected where.

share|improve this answer
This was the most helpful response, because it does not require re-partitioning the drive. Too bad Ubuntu doesn't create swap by default when you install it on a new machine! – Ernie Feb 27 at 17:34

(replace the "x" in sdax with swap partition number eg: sda5)

replace "xxx" with UUID number eg: 67682d1b-a1d8-4377-a3dd-67340c141619)

su (give password to get root permission)

blkid /dev/sdax (get UUID) mkswap /dev/sdax (format swap partition) swapon -U xxx

nano /etc/fstab (edit fstab) UUID=xxx none swap sw 0 0 (enter and save this text to make swap permanant) (then close fsantab)

nano /etc/initramfs-tools/conf.d/resume (create "resume" file and save this text to use hibernate/resume) RESUME=UUID=xxx (ctrl+x to close nano)->(y to save)

restart machine

login and now you can test hibernate / resume

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.