Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Today I discovered that my Ubuntu 12.04LTS doesn't have any swap-space.

I installed this system from scratch only some weeks ago. I encrypted all the partitions to me needs. I didn't install any swap space in the first place, cause the installation dialog misbehaved when I tried to set up the encrypted swap. I added the encrypted swap-space after finishing the installation by editing /etc/crypttab and /etc/fstab. I might issued some more commands to propagate the changes (I don't remember). The swap-space used to just work fine after that.

Today I discovered for coincidence that I don't have any swap available. There are no error messages.

Some system information: (swap is supposed to be on sdb1_crypt)


sda1_crypt UUID=91cb1de3-0754-4aa3-89b9-807e9a95a55a /root/keyfileToHome luks
sdb1_crypt UUID=96558522-6c79-4ddc-8f93-7defee6a9255 /dev/urandom cipher=aes-cbc-essiv:sha256,hash=ripemd160,size=256,swap
sdb2_crypt UUID=5fd25f3a-de63-4a5d-94a7-3e509a70b68c none luks


# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/mapper/sdb2_crypt /               ext4    errors=remount-ro 0       1
# /boot used to be on /dev/sdb3 during installation
UUID=9cdce42f-3894-4878-af03-12284dd5cab9 /boot           ext4    defaults        0       2
/dev/mapper/sda1_crypt /home           ext4    defaults        0       2
/dev/mapper/sdb1_crypt none            swap    sw              0       0

$ ll /dev/mapper shows me, that sdb1_crypt is actually not created:

total 0
drwxr-xr-x  2 root root     120 Sep 29 16:26 ./
drwxr-xr-x 16 root root    4460 Sep 29 16:26 ../
crw-------  1 root root 10, 236 Sep 29 16:24 control
lrwxrwxrwx  1 root root       7 Sep 29 16:24 sda1_crypt -> ../dm-1
lrwxrwxrwx  1 root root       7 Sep 29 16:24 sdb2_crypt -> ../dm-0

Therefor /proc/swaps is empty of course:

Filename                Type        Size    Used    Priority

I tried to update the initramfs:

# update-initramfs -u

That didn't help.

I am able to turn on the swap space temporarily by running the following commands:

# cryptsetup -d /dev/urandom create sdb1_crypt /dev/disk/by-uuid/96558522-6c79-4ddc-8f93-7defee6a9255
# mkswap /dev/mapper/sdb1_crypt
# swapon -a

I tried to add the output from dmesg here. I got an error message that the body of the message is too long. If it could be helpful, please ask for specific sections of the dmesg output.

What causes the problem? How can I fix it? How can I get the swap space work as usual again? Any help appreciated.

share|improve this question
Same think still happens on 14.04, and there is a solution. Just in case someone falls here: askubuntu.com/questions/462775/… –  adosaiguas Jun 1 '14 at 14:54

1 Answer 1

When setting up encrypted swap like this, you cannot use the "by-uuid" method as above, since the swap partition will be reformated with a random key every time your computer boots, and the UUID will change every time this happens.

The correct way to do this is to use another persistent method, for instance the "by-id" or the "by-path" method. If you list the contents of /dev/disk, you'll see four or five different entries (depending on your partition table type):

[root@computer~]# ls -lA /dev/disk/
total 0
drwxr-xr-x 2 root root 360 Feb 24 23:51 by-id
drwxr-xr-x 2 root root  80 Feb 24 23:51 by-label
drwxr-xr-x 2 root root  80 Feb 24 23:51 by-partlabel
drwxr-xr-x 2 root root 100 Feb 24 23:51 by-partuuid    # only available if your disk is GPT-formatted
drwxr-xr-x 2 root root 160 Feb 24 23:51 by-uuid
[root@computer ~]#

You never listed your original blkid or lsblk -f, but from your original post leads me to believe you have sdb1 is a luks-formatted partition, which volume you mount as swap. If so, when you list the contents of `/dev/disk/by-path/´ you should see something like this:

[root@computer ~]# ls -lA /dev/disk/by-id/
total 0
lrwxrwxrwx 1 root root  9 Feb 24 23:51 ata-MY_OTHER_HARD_DISK -> ../../sda
lrwxrwxrwx 1 root root 10 Feb 24 23:51 ata-MY_OTHER_HARD_DISK-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Feb 24 23:51 ata-MY_OTHER_HARD_DISK-part2 -> ../../sda2
lrwxrwxrwx 1 root root  9 Feb 24 23:51 ata-HARD_DISK_MAKE_MODEL -> ../../sdb
lrwxrwxrwx 1 root root 10 Feb 24 23:51 ata-HARD_DISK_MAKE_MODEL-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Feb 24 23:51 ata-HARD_DISK_MAKE_MODEL-part2 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Feb 24 23:51 ata-HARD_DISK_MAKE_MODEL-part3 -> ../../sdb3
lrwxrwxrwx 1 root root 10 Feb 24 23:51 dm-name-luks-12345678-abcd-1234-5678-abcdef123456 -> ../../dm-0
lrwxrwxrwx 1 root root 10 Feb 24 23:51 dm-uuid-CRYPT-LUKS1-12345678abcd12345678abcdef123456-luks-12345678-abcd-1234-5678-abcdef123456 -> ../../dm-0
lrwxrwxrwx 1 root root  9 Feb 24 23:51 wwn-0x1234567890123456 -> ../../sda
lrwxrwxrwx 1 root root 10 Feb 24 23:51 wwn-0x1234567890123456-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Feb 24 23:51 wwn-0x1234567890123456-part2 -> ../../sda2
lrwxrwxrwx 1 root root  9 Feb 24 23:51 wwn-0x5555444433332222 -> ../../sdb
lrwxrwxrwx 1 root root 10 Feb 24 23:51 wwn-0x5555444433332222-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Feb 24 23:51 wwn-0x5555444433332222-part2 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Feb 24 23:51 wwn-0x5555444433332222-part3 -> ../../sdb3
[root@computer ~]# 

From this output:

  • I have two disks, which make and model are "HARD_DISK_MAKE_MODEL" and "MY_OTHER_HARD_DISK", and which have "serial numbers" 1234567890123456 and 5555444433332222. In both cases, those are sda and sdb, respectively.
  • From the -partX suffix in each of them, you can also identify which partition is which, too.
  • These values are also unambiguous values to identify your partitions and disks, but they will NOT change, since they're based on hard values from your disks.

So, /dev/disk/by-id/ata-HARD_DISK_MAKE_MODEL-part2 will be the same partition, no matter if the disk is /dev/sda, /dev/sdb or if the partition is reformatted and it's UUID changes. This would be the best way to refer to your swap partition on crypttab, since it doesn't depend on anything recorded inside the partition.

Further references:

share|improve this answer
More explanations on dm-crypt and swap encryption: wiki.archlinux.org/index.php/Dm-crypt/Swap_encryption –  Guto Andreollo Feb 24 at 2:18
Welcome to Ask Ubuntu! ;-) Could you please edit your answer and incorporate your comment into it? Also, link-only answers can become 100% useless if that link is moved, changed, or the main site just disappears... :-( Therefore, please edit your answer, and copy the relevant steps from the link into your answer, thereby guaranteeing your answer for 100% of the lifetime of this site! ;-) You can always leave the link in at the bottom of your answer as a source for your material... –  Fabby Feb 24 at 7:38
Thanks for the pointer, @Fabby ! I edited the post with the explanation from the link, but unfortunately I can't add the third link, since I'm still <10 karma here. If you are able, feel free to do it! –  Guto Andreollo Feb 25 at 3:21
Now it just became an excellent answer to an excellent question and your reputation (not karma) magically went up! ;-) Keep up the good work! –  Fabby Feb 25 at 20:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.