Friday, September 1, 2017

Arch Linux not loading Kernel Modules with Cryptsetup/LUKS

You are likely to encounter this error when logging to an Arch Linux System just after a kernel update with a Cryptsetup and LUKS encrypted partition. Upon successful encryption password input to the Window Manager all the hardware inputs are unresponsive and nothing can be done unless switching back to the tty screen. Cryptsetup is utility used to conveniently setup disk encryption based on DMCrypt kernel module and LUKS is the standard for Linux hard disk encryption.

To tackle this issue one needs a live Arch Linux CD/USB flash drive with no fear of data loss. The following command steps shows how to go about it and getting back to the Window Manager.

Boot up the Linux system with the Live USB/CD to this prompt:

Unlock the encrypted partition:
cryptsetup luks0pen /dev/sda2 cryptroot

Create a directory to mount the decrypted partition to:
mkdir /mnt/arch

Mount the decrypted partition to the folder created above:
mount /dev/mapper/cryptroot /mnt/arch

Change the working directory to the one created:
cd /mnt/arch

Mount the file systems: 
mount -t proc proc proc/
mount -t sysfs sys sys
mount -o bind /dev dev/

Mount the boot partition:
mount /dev/sda1 boot/

Connect the box to the internet:
sudo wifi-menu

Change the root directory from the current LiveCD or USB to the Linux box:
chroot . /bin/bash

Update the box:
pacman -Syu && mkinitcpio -p linux

Exit the environment and unmount the partition :

Reboot the system, remove the LiveCD/USB flash drive and you are good to go.

To avoid the issue in future; when updating the kernel; one has to remember to use the mkinitcpio -p linux command argument after updating the system or simply:
pacman -Syu && mkinitcpio -p linux

Mkinitcpio creates an initial ramdisk environment. The initial ramdisk is in essence a very small environment (early userspace) which loads various kernel modules and sets up necessary things before handing over control to init. This makes it possible to have, for example, encrypted root file systems and root file systems on a software RAID array. mkinitcpio allows for easy extension with custom hooks, has autodetection at runtime, and many other features.


[root@e13olf]# exit