4

My system is freezing when the memory used is maxed out and I was wondering why. Turns out the swap is not being used. Here's my partition table:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63       80324       40131   de  Dell Utility
/dev/sda4           81918   909195263   454556673    5  Extended
/dev/sda5       512121690   909195263   198536787   83  Linux
/dev/sda6           81920     3987455     1952768   83  Linux
/dev/sda7         3989504   140705791    68358144   83  Linux
/dev/sda8       492589056   512120831     9765888   82  Linux swap / Solaris
/dev/sda9       140707840   492584959   175938560   83  Linux

The swap partition is not turned on and doesn't show in df but it does in the disks utility:

Filesystem             Size  Used Avail Use% Mounted on
udev                   1.9G  4.0K  1.9G   1% /dev
tmpfs                  392M  1.3M  391M   1% /run
/dev/sda7               65G   19G   43G  31% /
none                   4.0K     0  4.0K   0% /sys/fs/cgroup
none                   5.0M     0  5.0M   0% /run/lock
none                   2.0G   26M  1.9G   2% /run/shm
none                   100M   48K  100M   1% /run/user
/dev/sda6              1.9G   89M  1.7G   6% /boot
/dev/sda9              166G   47G  111G  30% /home
/home/my-user-name/.Private  166G   47G  111G  30% /home/my-user-name

enter image description here

$ sudo swapon -s
Filename                Type        Size    Used    Priority

As you can notice my Home partition is encrypted but I have not encrypted the swap.

Swap seems declared in /etc/fstab:

# swap was on /dev/sda8 during installation
#UUID=df55bf68-b824-4f21-83f3-dfa80a0b74ab none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0

I'd like to know why it's not working and how can I fix it?

Update It seems there's a reported bug on this for several releases and has not been fixed for 14.04 yet.

Here's the result of cat /etc/crypttab:

cryptswap1 UUID=df55bf68-b824-4f21-83f3-dfa80a0b74ab /dev/urandom swap,cipher=aes-cbc-essiv:sha256

And what was suggested by A.B.:

$ sudo /etc/init.d/cryptdisks reload
 * Stopping remaining crypto disks...                                                                    [ OK ]
 * cryptswap1 (stopped)...                   
 * Starting remaining crypto disks...
 * cryptswap1 (skipped, device /dev/disk/by-uuid/df55bf68-b824-4f21-83f3-dfa80a0b74ab does not exist)... [fail]
                                                                                                         [ OK ]
$ sudo swapon -a
swapon: /dev/mapper/cryptswap1: stat failed: No such file or directory

Based on David Foerster's answer I did cat /dev/disk/by-uuid/ and got 6 uuid's. Did blkid -U of each and non is /dev/sda8 which the swap is supposed to be. I got sda's 1, 5, 6, 7, 9, and /dev/mapper/luks-****. The last of which I think is the other encrypted partition that I left untouched during installation (was encrypted by 12.04).

I also tried the following answer. Did not work either.

Update: I ended up reformatting the partitions and re-installing the system. It seems working fine now.

user10853
  • 1,566

2 Answers2

2
cryptswap1 (skipped, device /dev/disk/by-uuid/df55bf68-b824-4f21-83f3-dfa80a0b74ab does not exist)

Whatever volume had UUID=df55bf68-b824-4f21-83f3-dfa80a0b74ab, when that /etc/crypttab entry was generated, doesn't exist any longer.

How to fix it

  • Run sudo swapoff -a just to make sure that all swap spaces are released. The output of swapon -s should now be empty (apart from a column header line).

  • Remove (or comment out) the lines about swap in /etc/fstab and /etc/crypttab. Make back-ups, if you're unsure.

  • You say you want to place swap on /dev/sda8. Ignore it's current content for the remainder of these instructions; treat is a garbage data. You will lose all data on sda8 in the process! Make a backup, if you value it!

  • Set up a new swap space on /dev/sda8, either unencrypted or encrypted.

My previous advice (please use the above one instead)

Since raw devices (or raw dm-crypt devices) don't have UUIDs, you'll need to resort to other device identifiers. Kernel names (/dev/sd* and friends) aren't stable across boots, so your best bet is to find the entry inside /dev/disk/by-id/, that links to your intended encrypted swap partition. Those are stable enough in my experience (barring changes in the kernel or udev scripts).

Assuming that /dev/sda8 is the intended place for the encrypted swap partition, you can find it's ID-based path(s) in the output of

ls -l /dev/disk/by-id/* | grep sda8

or more elaborately with:

find -L /dev/disk/by-id -samefile /dev/sda8

You can use one of the results for the second column of the crypttab entry.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • updated based on your answer. – user10853 Dec 29 '15 at 17:30
  • On which partition do you want to have the encrypted swap partition? – David Foerster Dec 29 '15 at 17:34
  • blkid without sudo is useless ;) – A.B. Dec 29 '15 at 17:35
  • @A.B. I did sudo. @David: my swap in "Disks" & fdisk shows as sda8. And I did use the uuid's not the /dev/sda*. I used cat /dev/disk/by-uuid/ to get the uuid's and then sudo bkid -U **** to get the /dev/sda* – user10853 Dec 29 '15 at 17:49
  • @user10853: Mounting that dm-crypt device and using it as swap space will sooner or later overwrite the header of the unencrypted swap partition, which holds the UUID. Overwriting with encrypted data will look like garbage and not announce a UUID to the system. You need to use a different method to identify your swap partition in crypttab. – David Foerster Dec 29 '15 at 18:03
  • I don't know what to do based on your comment. Isn't it possible to format the partition and recreate the swap for the system? – user10853 Dec 30 '15 at 21:49
  • I understand it was convoluted and unnecessary. See my update. – David Foerster Dec 31 '15 at 01:04
-2

I think you have an error in your /etc/fstab file. You swap does not have mount point.

Change the line

/dev/mapper/cryptswap1 none swap sw 0 0

to

/dev/mapper/cryptswap1 swap swap defaults 0 0
Quentin
  • 1,307
  • 1
    it doesn't appear in swapon does it require a reboot? also according to https://help.ubuntu.com/community/Fstab#Fstab_File_Configuration swap doesn't require a mount point. – user10853 Dec 28 '15 at 16:07
  • You are right. Maybe a mistake in my own fstab. An other difference with mine, the mount right have defaults value instead of sw. Edited on my previous post. And yes you need to reboot after update your fstab (or sudo mount -a but I am not sure it's works for swap partition) – Quentin Dec 28 '15 at 19:40
  • /dev/mapper/cryptswap1 swap swap defaults 0 0 ??? – A.B. Dec 28 '15 at 20:30
  • And why is swap a mount point and why is a swap partition mounted? – A.B. Dec 28 '15 at 20:40
  • And no, you don't need a reboot! – A.B. Dec 28 '15 at 20:43
  • didn't work. Updated post. – user10853 Dec 29 '15 at 16:40
  • -1 The entry of seconds column in fstab is irrelevant for swap partitions. I have it set to none on my system and it works fine. – David Foerster Dec 29 '15 at 17:05