7

I installed 15.04 onto a lvm partition with the mount point / and /boot onto a separate unencrypted partition.

Can someone list the steps (clearly please) to set up a swap partition post-install? It would be helpful also to see the steps for both an encrypted swap and non-encrypted swap.

Thank you!

gordon50
  • 110

2 Answers2

6

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

Maythux
  • 84,289
  • blkid shows me this: /dev/sda6: UUID="e2342vda-c324-2434-324c-84723ff298c" TYPE="crypto_LUKS" PARTUUID="98274938-4e32-4etf-9e32-0938g8342" How do I add this into the fstab properly? – gordon50 May 28 '15 at 11:10
  • UUID=e2342vda-c324-2434-324c-84723ff298c none swap sw 0 0 – Maythux May 28 '15 at 11:20
  • By simply adding this line into fstab, when I boot ubuntu, enter my drive encrypt passphrase and login, will it recognize the encrypted swap partition as such? I assume once I login I will need to unlock the swap partition. – gordon50 May 28 '15 at 11:35
  • I assume that the next step is to tell the system to use this swap? – gordon50 May 28 '15 at 11:45
  • How about: sudo swapon ? – gordon50 May 28 '15 at 11:48
  • using: sudo swapon -a

    I receive the following message: swapon: /dev/sda6: read swap header failed

    – gordon50 May 28 '15 at 21:12
  • How do I make the swapfile permanent? It forgets the swapfile after a while. Not sure if that's after a reboot or after installing a system update that replaced the kernel. – simbabque Aug 19 '15 at 07:35
1

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?

gordon50
  • 110