How to create a swap partition if I already have 4 primary partitions?

Solution 1:

You do not need a swap partition: you can just as well use a swap file. There is no performance difference between a swap partition and a swap file. To add a swap file:

  1. Create the file (in this example, a 4 GiB file named /swapfile):

    sudo fallocate -l 4G /swapfile
    
  2. Format it as swap:

    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    
  3. Enable swapping on the new swap file:

    sudo swapon /swapfile
    
  4. Add the newly created file to /etc/fstab by appending /swapfile none swap sw 0 0 to /etc/fstab.

See the Digital Ocean tutorial How To Add Swap on Ubuntu 14.04.

Solution 2:

If you want a swap partition, and not just a swap file, you will need to reformat one partition into an extended partition, and then you will have to create logical partitions within that.

Then once you get to installing, use LVM for even more partitioning fun and flexibility!