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.

When I installed Ubuntu, I setup an encrypted home partition. Now I have come to an issue where I am running out of memory because I haven't setup swap. How can I setup an encrypted swap file?

A couple of times while booting I've seen some reference to cryptswap. I've also got these lines contained in /etc/fstab

# swap was on /dev/sda6 during installation
#UUID=1ba8a53b-1842-4de7-8e38-2d6c79f3a1ab none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0
share|improve this question

1 Answer 1

up vote 9 down vote accepted

Thanks to this guide I have setup an encrypted swap file (can't be used for hiberation).

  1. Firstly create an appropriately sized (I used 8GB) file to store the swap data.

    truncate -s 4GB /cryptswap

  2. Generate the swap using mkswap.

    mkswap /cryptswap

  3. Install a necessary package. apt-get install cryptsetup

  4. Add the following to /etc/fstab

    /dev/mapper/cryptswap none swap sw 0 0

  5. Add the following to /etc/crypttab

    cryptswap /cryptswap /dev/urandom swap

  6. Activate the new encrypted swap file.

    /etc/init.d/cryptdisks reload

    swapon -a

share|improve this answer
This encrypted swap is the only secure option for hibernation. With a little change to /etc/crypttab and a startup script (to ask user for mount password) –  Adam Ryczkowski Feb 5 at 15:23

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.