Sunday, November 2, 2014

Making custom initramfs supporting encrypted lvm partition

First of all, create directory with basic Linux directory tree:
mkdir -p initramfs/{dev,proc,sys,mnt,etc,bin,sbin,run}
In root directory create executable init script, check my init.txt.
Copy statically linked busybox to the /bin, you can chroot inside initramfs and call:
busybox --install -s /bin
You can compile static busybox with (gentoo):
USE="static" emerge busybox
Copy statically linked lvm and cryptosetup to /sbin and now it should work.
Now call:
find . | cpio -H newc -o > ../initramfs.cpiocat ../initramfs.cpio | gzip > ../initramfs.igz
Add new boot menu entry in /etc/grub.d/40_custom:
menuentry "encrypted" {
set root='(hd0,1)'
  linux /vmlinuz-3.13.6-gentoo root=/dev/sdb6
  initrd /initramfs-3.13.6-gentoo
}
Cryptsetup didn't work while being statically linked with libgcrypt-1.6.1 (causing segmentation fault).

Feel free to leave a comment below!