Since your USB drive is also your boot drive, the system only loads the initramfs image to memory until the root partition is decrypted and newroot
is remapped. This is where manual mount of the USB drive would be necessary from within the initramfs or an update to fstab
needs to be made to mount the partition which contains the key file. Although you mentioned that that during boot it is stored in /boot/header.img
it's because the USB is no longer mounted when the initramfs is loaded into RAM for the boot processs. Therefore when crypttab
initiates, cryptsetup
cant find the /boot/header.img file because the directory for /boot on the USB hasn't been mounted within the initramfs environment which is currently loaded to decrypt your hard drive's root folder.
To be sure, as telcoM explained, if you previously booted into your system and created a keyfile while the OS was unlocked and the partition was decrypted and then placing a copy of the keyfile.img within your /boot
directory at that point in time (and again, and this is while the system is unencrypted and you're already accessing the system) then it's not the same /boot
directory you find when you're booting up and the USB contains the boot drive; that's what we're both trying to say. This is because during the boot process, it has opened and copied the initrd-4.15.33-generic image (for example) and does not mount automatically the USB device as a storage container.
So to resolve, you need fstab
to mount the USB to the /boot
directory so that crypttab
can locate the directory when it's called for by cryptsetup
See the fstab man page for explanations if needed for below:
e.g.
# First find the UUID of the partition holding your USB thumb drive
$ blkid
# You can also use grep or whatever you're more comfortable with as a text editor
$ nano /etc/fstab
# then add a line for your USB device
UUID={device partition UUID} {mount point} {filesystem} {mount options} {dump order}{fsck order}
# Example
UUID=66E53SSD988 /boot ext4 defaults 0 1
However, I would suggest mounting the drive somewhere other than in the /boot directory unless that's just the directory within the USB and then modifying crypttab so that there's less confusion between what folder the header.img file is in.
i.e.
UUID=66E53SSD988 /mnt/usb ext4 defaults 0 1
Then, in the case of the changed mount point, crypttab
would in turn need to be changed to the following :
crypt_device /dev/sda luks,header=/mnt/usb/boot/header.img