1

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

1 Answers1

3

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

Tobias
  • 1,678