Simple initramfs with luks support

mkdir /usr/src/initramfs # Basic directories structure mkdir --parents /usr/src/initramfs/{bin,dev,etc,lib,mnt/root,proc,root,sbin,sys,usr/lib} # Minimal stuff needed cp --archive /dev/{console,null,random,tty,urandom,sda,sda1,sda2,sda3} /usr/src/initramfs/dev/ cp --parents /proc/sys/kernel/printk /usr/src/initramfs/ cp --parents /etc/fstab /usr/src/initramfs/

Binary / library

bin/busybox, sbin/cryptsetup, sbin/switch_root and sbin/init

For binary build dynamically, copy library and simlink into their respective path

Bash script init

A init as simple of init will work

Place the init file at the root of the initramfs directory and apply a chmod +x

Generate the initramfs

A the root directory of the initramfs directory, execute

find . -print0 | cpio --null --create --verbose --format=newc > /boot/initrd-{KERNELVERS}.cpio

Extra

To automatically keep your binary/library up to date, you can use libbin placed at the root directory of your initramfs.

Grub entry

A simple as

menuentry 'Gentoo' { insmod part_msdos insmod crypto insmod cryptodisk insmod luks insmod cpio set root='hd0,msdos1' linux /vmlinuz-4.19.152 luks enc_root=UUID={UUID_CRYPTO_LUKS} root=UUID={UUID_ROOT} initrd /initrd-4.19.152.cpio }