If I check the usage of the swap partition in my OS (Ubuntu 14.04)

$ cat /proc/swaps 
Filename                Type        Size    Used    Priority

I obtain an empty result. But this partition should actually exist, named /dev/sda6 and as large as 8 GB.

$ sudo parted
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print free
Model: ATA Hitachi HTS54323 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size        Type      File system    Flags
        32,3kB  1049kB  1016kB                Free Space
 1      1049kB  160GB   160GB       primary   ext4           boot
        160GB   160GB   1048kB                Free Space
 2      160GB   320GB   160GB       extended
 5      160GB   312GB   152GB       logical   ext4
 6      312GB   320GB   7997MB      logical
        320GB   320GB   352kB                 Free Space

In partition number 6 the File system is empty and it should be instead linux-swap. These partitions were created with the Ubuntu installation wizard. Is there something wrong? And how to use that 8 GB space as a swap partition?

As requested in the comments, this is the contents of /etc/fstab.

$ cat /etc/fstab
# /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>
# / was on /dev/sda1 during installation
UUID=bd20abfc-6ff1-4c3c-a77d-0e85f5c19af9 /               ext4    errors=remount-ro 0       1
# /home was on /dev/sda5 during installation
UUID=29599282-3815-4aa7-80ba-9058898e7a73 /home           ext4    defaults        0       2
# swap was on /dev/sda6 during installation
#UUID=c34d62e9-68e8-495a-869b-b107b5741c7e none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0

During the installation I choose to encrypt my home directory (then I choose to made it later and I never did it). I don't remember the encryption of the swap too! I don't need an encrypted swap partition.


$ cat /etc/crypttab 
cryptswap1 UUID=c34d62e9-68e8-495a-869b-b107b5741c7e /dev/urandom swap,cipher=aes-cbc-essiv:sha256
$ free -m
             total       used       free     shared    buffers     cached
Mem:          3005       2082        922         42         46        534
-/+ buffers/cache:       1500       1504
Swap:            0          0          0
  • @StephenKitt Sure, I made it as requested. – BowPark Sep 6 '16 at 10:15
  • Thanks; could you also add the contents of /etc/crypttab (if there's nothing sensitive there)? – Stephen Kitt Sep 6 '16 at 10:37
  • What's the output of free -m ? – SHW Sep 6 '16 at 10:51
  • @StephenKitt Yes, it has nothing "private"; I never even choose a key for encryption here. – BowPark Sep 6 '16 at 13:01
  • @SHW I edited my post with that output – BowPark Sep 6 '16 at 13:05

As mentioned by Jan Henke, this is a known bug for Ubuntu 14.04 (and 12.04). If during installation the user chooses to encrypt his home partition, the swap partition will be encrypted too, but it will be not available to the OS.

A direct mkswap may not work (as suggested by Stephen Kitt), because of the encryption of the interested partition.

The solution that worked for my system was the following:

  1. Run sudo fdisk -l and find the partition maked as swap partition. In this example, /dev/sda6 will be used. If you found another partition, use its name instead of sda6 in all the steps!
  2. Compare its name with the partition used as swap during the installation (so, before encryption), shown in /etc/fstab in the line (1)

    # swap was on /dev/sda6 during installation

    and make sure they are the same.

  3. Run sudo -s and then umount /dev/sda6.

  4. Run mkswap /dev/sda6. In the output, a UUID should be produced.

  5. Use that UUID to run

    echo "RESUME=UUID=143c43d8-0a77-4d62-a7ae-f53a8e0229a9" > /etc/initramfs-tools/conf.d/resume

    (the UUID used here is just an example).

  6. Run

    echo "cryptswap1 /dev/sda6 /dev/urandom swap,cipher=aes-cbc-essiv:sha256" > /etc/crypttab

  7. Run

    update-initramfs -u exit

  8. Reboot.

After rebooting, verify that your system is actually using a swap partition. Check it with cat /proc/swaps or swapon -s. The output of the latter command should be like the following:

Filename                                Type            Size    Used    Priority
/dev/mapper/cryptswap1                  partition       8787964 0       -1

This solution is from this link. I rewrote it entirely here according to the Stackexchange guidelines.

(1) In my question I posted all the contents of my /etc/fstab file.

  • I think that you're missing a step here for creating the cryptswap1 dev mapper. I believe you need to run the command sudo ecryptfs-setup-swap after I ran that I was able to get the /dev/mapper/cryptswap1 that pointed to /dev/dm-0 after the running of the update-initramfs -u and the reboot. – Terrance Jun 13 '18 at 14:44
  • Why do you create file /etc/initramfs-tools/conf.d/resume? Resume from hibernate will not work with encrypted swap anyway. If it is not used, then also step 7 is not needed. – jarno Jun 21 '18 at 23:47

That is a well known problem with encrypted swaps on Ubuntu. In the default setup it often fails to mount the swap on boot.

If I remember correctly, you can add the noauto option to the swap entry in /etc/fstab, then edit your /etc/rc.local and add these lines to it (before the return 0 at the end, it is important to keep that)

sleep 1
swapon /dev/mapper/cryptswap1

That worked for me, but I am not sure any more if it required recreating the swap partition or not. Am also no longer using Ubuntu, so the above solution is from my memory from the time I was affected by that problem too.


You need to execute the commands:

# mkswap <Your_Swap_Partition>
# swapon <Your_Swap_Partition>

You just have created the partition but not yet formatted with file system type.

  • No, /etc/fstab points to an encrypted swap... – Stephen Kitt Sep 6 '16 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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