This question already has an answer here:

I installed my OS but did not create a swap space. I now realize it is a problem. I have a 4GB ram and I will running huge applications. The below is the snip of my gparted. I opened Gparted but could not find swap on. I saw the accepted answer to this question. Will it work for me. In laymen terms, If I use those two commands can I forget about swap space and related things. Even more laymen, If I shutdown my system and restart it, will i then have to worry about swap space.

enter image description here

marked as duplicate by c0rp, Eric Carvalho, Mitch Dec 15 '14 at 8:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    I'm not sure I understand your question. If you follow the answer you link to, and run the two commands, you will set up swap in a file (2GB worth of swap), and it will be added to the /etc/fstab, so it will be activated every time you startup the machine. Was that your question? Or are you asking for help to create a swap partition? Please edit your question to clarify. – Tobias Dec 11 '14 at 8:47
  • Ok, So run those two commands and my problem with swap will be over. Thanks. And i have doubt creating a swap partition too. can i make that allocated 4 gb as swap partition? – WannaBeCoder Dec 11 '14 at 8:51
  • 1
    I don't believe he's asking for a swap partition in particular. – Tobias Dec 11 '14 at 9:03
  • @Sneetsher I am unable to find swap on. – WannaBeCoder Dec 11 '14 at 9:08
  • 1
    @WannaBeCoder, the easiest way is to use swap file, see Tobias comment above. If you want to use that 4GB space, you have remove one primary partition then create extended partition 1st, see Tobias in below answer. – user.dz Dec 11 '14 at 9:19

You can either go with a swap file, like the answer to the question you link to, or you can add a swap partition.

Using a swap file: Command borrowed from #Qasim in Does it make sense to create swap partitions for new installations nowadways?

First switch to the root user

sudo su

Then run the following command

mkdir /swap && cd /swap && fallocate -l 2g 2GB.swap && mkswap 2GB.swap && swapon 2GB.swap && echo "# # # Swap File # # #" >> /etc/fstab && echo "/swap/2GB.swap    none                   swap               sw                       0       0" >> /etc/fstab && mount -a 

This will first create a folder called /swap, then enter the folder and add a 2 GB swap file. Then it will activate the swap file, and at last, it adds an entry to /etc/fstab that ensures this happens every time.

Using a swap partition: Seeing as you are using an MS-DOS partition table, you can not have more primary partitions. In order to make a swap partition, you will have to 'temporarily' delete one of your partitions. So first back up your data from that partition, then in gparted, delete the partion.

Right click on the now unallocated space and create a new partion, make sure to choose 'Logical' partition.

This logical partition can contain a lot of primary partitions, so now you can create a partition similar to the one you deleted, and add the swap partition next to it.

Once the swap partition is created, you can activate it with sudo swapon /dev/sda5 (replacing /dev/sda5 with the actual name of the partition).

To ensure that it is activated every time you boot, you'll have to edit /etc/fstab

sudo nano /etc/fstab

Add a new line with the following text, replacing /dev/sda5 with the name of your device:

/dev/sda5 none swap sw 0 0

Save with CTRL+O, then close with CTRL+X


-> Create a new partition at your unallocated space.

-> Remember your new partition's name (should be /dev/sda5).

-> Open up a shell

-> Type sudo mkswap /dev/sda5

-> Then mount it as swap using sudo swapon -U UUID

(Replace UUID with the one you get from blkid /dev/sda5)

-> Now edit the FSTAB to automatically mount your new swap

sudo nano /etc/fstab

Add this line to the end of fstab:

UUID=YOURUUID none swap sw 0 0

(Again: Replace YOURUUID with the one from blkid /dev/sda5)

Press STRG+O and then ENTER to save the file.

Press STRG+X to exit nano.

-> Now we prepare the swap for hibernation

sudo nano /etc/initramfs-tools/conf.d/resume

Edit the UUID at RESUME=UUID=xxx. with the one you got from blkid /dev/sda5

Save (STRG+O , ENTER) and exit (STRG+X) nano.

Last update your initramfs using sudo update-initramfs -u

  • Please note that your solution will not work if he's using a MS DOS partition table, as he already has 4 primary partitions. – Tobias Dec 11 '14 at 8:55
  • Yes. I can only have four partitions. – WannaBeCoder Dec 11 '14 at 8:56
  • Why are you installing Windows on sda2 and have an (E:) drive on sda4 ? They are on the same harddrive. Makes no sense – sn0w Dec 11 '14 at 8:59
  • 1
    If you want to go down this road, you will have to get rid of one of your partitions temporarily, in order to create a logical partition, to allow for more partitions than 4. So you will have to 1: Remove a partition (back up the data first) 2: Create a new logical partition (it's an option in gparted) 3: Recreate your old partition under the new logical partition 4: Create another partition of the type 'swap' next to the other partition you just created. 5: Follow the instructions in the answer, replacing /dev/sda5 with the correct number, and skipping the first command. – Tobias Dec 11 '14 at 9:06
  • 1
    I don't believe this is the right place for this discussion, but if Windows is already installed, there will be an option during installation called 'Install Ubuntu next to Windows', this generally ends up adding the Windows boot entry to the GRUB menu as well. – Tobias Dec 11 '14 at 9:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.