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

5
  • 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, 2014 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? Dec 11, 2014 at 8:51
  • 1
    I don't believe he's asking for a swap partition in particular.
    – Tobias
    Dec 11, 2014 at 9:03
  • @Sneetsher I am unable to find swap on. Dec 11, 2014 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, 2014 at 9:19

1 Answer 1

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

Not the answer you're looking for? Browse other questions tagged .