Thursday, July 31, 2014

Swap partition always unknown on Ubuntu system

After upgrading the system from Ubuntu 13.10 to 14.04 LTS, or even installing ver. 14.04 fresh, sometimes it causes the swap partition to be damaged or unknown by the system, which prevents the system from using the swap partition.

I've tried many times to re-create & re-enable the swap partition which worked fine till I rebooted my system to figure out again that it's not been recognized by the system. Also will show in the System Monitor => Resources, the Swap "not available" [see img-1],


img-1
I'll try in this article to show you how to fix and enable the encryption in the swap partition. 

Follow the steps below.

1- Click Ctrl+Alt+T keys to open a Terminal window, we need now to stop the swap by typing this command: "sudo swapoff -a"

2- In my case, gparted utility shows my swap partition corrupted [see img-2] so I need to format it again as Linux-swap type, you can use gparted utility, in the terminal write this command: " gksu gparted"


img-2
3- on gparted right-click on the linux-swap partition after formatting it and select from the pop-up menu "swapon"
4- Run "sudo swapon -s" command to make sure the swap is enabled. now if you check the System Monitor you will see the system started using the swap area. [see img-3].
img-3
5- Run "sudo blkid" command to list the unique UUID for the swap partition, which we need to confirm later on.


6- now, we need to confirm the same UUID is used in the filesystem table, by running the following command: "sudo cat /etc/fstab"
in the line before the last one the swap line is hashed or remarked with "#" which means system will not execute this line also the used UUID is wrong "UUID=aa27439a-c1f2-4a91-8ff3-9869ab88e63f", coz this for the old swap partition before the format, we already re-formatted the swap partition so new UUID has been generated for the swap partition, now we must modify the "fstab" file to changed the swap UUID with the new one which will allow the system to auto mount the swap partition when we boot the system. Also we must remove the old encryption line which is the last line in the file.

7- Run "sudo gedit /etc/fstab" and do the following:
7.1- Remove the last line which points to the old encryption "/dev/mapper/cryptswap1 none swap sw 0 0"
7.2- Replace the old UUID for the swap "UUID=aa27439a-c1f2-4a91-8ff3-9869ab88e63f" with the new UUID which listed after we run the "blkid" command above "UUID=206a4ee5-e8e4-4501-aa31-2448b283d3b4"
7.3- Now remove the "#" mark from the swap UUID line which is the last line in our case

7.4- Save the file, then run this command again "sudo cat /etc/fstab" to make sure the "fstab" file is changed and saved, so the new file should look like the below image [img-4]


img-4
8- Reboot the system to make sure that the swap partition will automatically be mounted and used by the system. by running the System Monitor again, in my case I see the swap is running well as in [img-4] above.

We can run again steps # 5 & # 7 above to make sure the UUIDs for the swap are matching.

Great all is ok.

Now if you are encrypting your /home, I strongly recommend you encrypt your swap partition as well, otherwise your data wont be protected as your swap area could be a leake point. So below steps will be used to encrypt the swap part

If you are upgrading your system & your previous system you had encrypted swap, and you try to encrypt your swap now by running this command "ecryptfs-setup-swap" your encryption setup may fail and show an error message like the below image [img-5].

img-5
to make sure your encrypt table is empty or not, run this command "sudo cat /etc/crypttab", if it shows data something like below image [img-6], then your encryption setup will not run correctly:
img-6
and to fix this you must empty the encrypt table then run the encryption setup by running the following steps:

9- Run "sudo gedit /etc/crypttab", then delete all the lines in it then save it. (make backup of the original file before you do this)
10- Reboot your system

11- Now, run the encryption wizard "sudo ecryptfs-setup-swap" and follow the wizard, then reboot.

No comments:

Post a Comment