Add a swap partition post-install 15.04

Solution 1:

First you have to shrink the LVM volume

Read this to learn how. you can either use the answer marked or use gparted with version > 0.14.

One you shrink the LVM you can know create a new partition for swap using Gparted.

Now it's time to add this newly create parition to fstab

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

sudo gedit /etc/fstab

You need to add a line that looks like

UUID=new-partition-UUID none   swap    sw      0       0

You can get the UUID using the command

sudo blkid /dev/sdaX

Where sdaX stands for the newly created partition



Another workaround is to create a swap file instead of a swap partition.

in this i'm going to create a 4G swap file

sudo fallocate -l 4G /swapfile

verify that the correct amount of space was reserved by typing:

ls -lh /swapfile

output should be

-rw-r--r-- 1 root root 4.0G Apr 28 13:19 /swapfile

To enable the swap file:

sudo chmod 600 /swapfile

Verify that the file has the correct permissions:

ls -lh /swapfile

output should be:

-rw------- 1 root root 4.0G Apr 28 17:19 /swapfile

Now teell system to set up the swap space:

sudo mkswap /swapfile

output would be like:

Setting up swapspace version 1, size = 4194300 KiB no label, UUID=e2f1e9cf-c0a9-4ed4-b8ab-714b8a7d6944

Our file is now ready to be used as a swap space. We can enable this by typing:

sudo swapon /swapfile

We can verify that the procedure was successful by checking whether our system reports swap space now:

sudo swapon -s

output would be like:

Filename                Type        Size    Used    Priority
/swapfile               file        4194300 0       -1

source

Solution 2:

This solved the problem and worked to setup unencrypted swap but I just want to clarify the steps I took.

  1. In gparted - formated a partition as the type - linuxswap
  2. In terminal I ran "sudo blkid /dev/sdaX" to copy the UUID of the swap partition.
  3. I edited /etc/fstab and add the new swap partition by adding the line UUID=new-partition-UUID none swap sw 0 0
  4. ran "sudo swapon & sudo swapon -a & sudo swapon -s"
  5. rebooted the computer and voila! - verified using ActivityMonitor

Now the question remains, how does one encrypt the swap drive?