Ubuntu – cryptsetup: waiting for encrypted source device /swapfile

bootencryptionfstabmountpartitioning

I know this has been asked but I am asking this because the fix i found didnt work.
I got the same problem this person had: Ubuntu 19.04 "waiting for encrypted source device /swapfile" and then initramfs prompt on boot : linuxquestions

but i tried the fix which was to add "size=256" in /etc/crypttab.
I did that, but it still warns me that I haven't specified size in crypttab and still takes time to boot. (my computer will still boot to a working gui if i type exit at the prompt)

Here's the contents of /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/nvme0n1p2 during installation
UUID=694b4858-ead8-400d-9406-f9fc45dc71f1 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=CA5F-286C  /boot/efi       vfat    umask=0077      0       1
#/swapfile none            swap    sw              0       0
#/dev/mapper/cryptswap1 none swap sw 0 0
#/swapfile swap swap defaults 0 0
/dev/mapper/cryptswap1 none swap sw,pri=100 0 0

and here is /etc/crypttab:

# <target name> <source device>     <key file>  <options>
cryptswap1 /swapfile /dev/urandom swap,offset=1024,cipher=aes-xts-plain64,size=256

does it help that it worked all the time before but just doesnt now, and that i had to use Ubuntu recovery mode DPKG before I edited /etc/crypttab?

Any help would be VERY appreciated. TY in advance!

edit: it would be nice if i could keep swap as i only have 5.7gb ram (2.3gb ram is system reserved)

Best Answer

The root cause and explanation, why above workaround works, is that initramfs cryptroot hook (/usr/share/initramfs-tools/hooks/cryptroot) is trying to translate /swapfile to block device when you have cryptswap in /etc/crypttab. This obviously fails as /swapfile is not a device and is not available during the time when initramfs runs.

As you are not using encrypted rootfs (otherwise /swapfile would be already encrypted as part of it) the easiest way is to disable this cryptroot hook. Unfortunately there is no nice way, how to do it. The best way I found was to insert exit 0 into /etc/cryptsetup-initramfs/conf-hook as this script is sourced by the cryptroot hook.

Related Question