On a fresh install of Ubuntu 14.04, I get this error message during boot
the disk drive for /dev/mapper/cryptswap1 is not ready yet or not present
and the swap partition is never activated. From my searches so far I have found:
- It is a widespread problem, probably affecting every Ubuntu 14.04 install on which encrypted swap was activated.
- Part of the problem is an easy to fix bug causing the encrypted swap header (generated during boot) to overwrite the unencrypted swap header, which makes it impossible to find the correct partition again during the next boot.
- All the proposed solutions to get it work appears to be simply workarounds amounting to: 1. Disable swap by setting it as noauto in fstab. 2. Create an /etc/rc.local file (or define your own service to be activated during boot), which activates the swap partition.
Is it possible to use encrypted swap on Ubuntu 14.04 without using this sort of hack? I am perfectly comfortable updating all the installed packages and fix those configuration files, which got initialized with incorrect content due to buggy install scripts. I'd rather avoid having to use my own script to activate swap, as that sort of approach have a tendency to break when packages are updated.
This is what my /etc/crypttab
looks like:
cryptswap1 /dev/sda6 /dev/urandom swap,cipher=aes-cbc-essiv:sha256,offset=16
And the relevant line from my /etc/fstab
is:
/dev/mapper/cryptswap1 none swap sw 0 0
What I have tried so far:
I have found message disk drive for /dev/mapper/cryptswap1 is not ready yet or not present even after trying various options asking about what might be the same scenario.
But the only answer is suggesting to using un-encrypted swap.
I have found http://ubuntuforums.org/showthread.php?t=2200995 which claims to have a solution, but the solution makes no sense to me.
The first part of the proposed solution is to rewrite the encrypted swap header using mkswap. However since this header is encrypted with a key, that is not persistent across reboots, this step wouldn't help getting the swap working after the next reboot.
It also suggests updates to /etc/fstab, but it appears my fstab is already looking correctly.
The post assumes LVM, which I do not use. I am unaware of any way, that would make a difference.
I have found https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/1310058 which helped me understand the issue with the swap header being overwritten and that adding offset
to crypttab
and regenerating the unencrypted swap header, can resolve this problem.
However the overwritten header is not the only issue at play, there is another issue, which I do not fully understand yet.
Other things I have found out about the problem:
From reading /lib/cryptsetup/cryptdisks.functions
I learned that during boot, the device is supposed to be created using the name cryptswap1_unformatted
then the encrypted swap header is to be written, and the device is to be renamed as cryptswap1
. In the kernel log I find this error message:
[ 39.419429] device-mapper: ioctl: Unable to change name on mapped device cryptswap1_unformatted to one that already exists: cryptswap1
Confusingly the outcome of that turns out to be that the device does end up having the name cryptswap1
, but the swap
header never got written.
Swap works during those boots where a file system check was performed. It is only when no file system checks is performed, that I get the dreaded cryptswap1 is not ready yet
error.
In /var/log/upstart/cryptdisks.log
I find the error message
Device cryptswap1_unformatted already exists.
However by adding some additional logging to /lib/cryptsetup/cryptdisks.functions
, I learned that there is a race between /etc/init.d/cryptdisks-early
and /etc/init/cryptdisks.conf
. Any logging I add to cryptdisks.functions
can influence how the actions of the two scripts are interleaved, and occasionally, it ends up working.
It is clear that the two are not supposed to be handling the same device in parallel. How can I get the two scripts serialized, such that swap works on every boot?
/dev/mapper/ubuntu--vg-swap_1 none swap discard,sw 0 0
– jmiserez Mar 15 '15 at 11:53/dev/sda6
was formatted as a swap partition? Also, I also get that message occasionally on startup, but still have encrypted swap. Also, have you triedsudo swapon -a
? – saiarcot895 Mar 15 '15 at 12:28/dev/sda6
was formatted as a swap partition before that machine even saw an Ubuntu install. The swap header on/dev/sda6
did however disappear due to the bug I mentioned with the generation ofcrypttab
. I have fixed thecrypttab
and runmkswap
on/dev/sda6
. I am trying to get the other problem resolved, which is the race condition during boot causingcryptswap1_unformatted
to get renamed tocryptswap1
beforemkswap
has been run on the swap device. – kasperd Mar 15 '15 at 12:35