logo

blog

My website can't be that messy, right? git clone https://anongit.hacktivis.me/git/blog.git/

Entire Disk Encryption with LUKS and ZFS.xhtml (3611B)


  1. <article xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="h-entry">
  2. <a class="u-url" href="/articles/Entire%20Disk%20Encryption%20with%20LUKS%20and%20ZFS"><h1 class="p-name">Entire Disk Encryption with LUKS and ZFS</h1></a>
  3. <p>Note: this is done from my current system, notes and my mind.</p>
  4. <p>
  5. This tutorial is for people that know how to install gentoo.
  6. By Entire Disk Encryption I mean that even the <code>/boot</code> is encrypted (although grub isn't).
  7. </p>
  8. <h3 id="disk-setup">Setup the disk <a href="#disk-setup">§</a></h3>
  9. <ul>
  10. <li>Disk: /dev/sda, sda1: BIOS Boot(2M+) / EFI System, sda2: Linux</li>
  11. <li>LUKS container: $hostname</li>
  12. <li>Zpool: $hostname</li>
  13. <li>Your username: haelwenn</li>
  14. <li>temporary mountpoint: /mnt/gentoo</li>
  15. <li>UUID of your clean GPT table: 1c578f43-6f16-497c-ba88-986609ffa1d6</li>
  16. </ul>
  17. <p>
  18. Picked LUKS1 because LUKS2 with GRUB is still too unstable and GRUB error messages are pretty bad, so better pick a safe one.
  19. </p>
  20. <pre><code>cryptsetup --type luks1 --cipher aes-xts-plain64 --key-size 512 --hash sha512 --verify-passphrase luksFormat /dev/sda2
  21. cryptsetup open /dev/sda2 $hostname
  22. zpool create -f -O compression=lz4 -m none -R /mnt/gentoo $hostname /dev/mapper/$hostname
  23. zfs create $hostname/ROOT
  24. zfs create -o mountpoint=legacy $hostname/ROOT/gentoo
  25. mkdir /mnt/gentoo
  26. mount -t zfs $hostname/ROOT/gentoo /mnt/gentoo
  27. zfs create -o mountpoint=/home $hostname/HOME
  28. zfs create $hostname/HOME/haelwenn
  29. zfs create -o mountpoint=/root $hostname/HOME/root
  30. zfs create $hostname/GENTOO
  31. zfs create -o mountpoint=/var/cache/distfiles $hostname/GENTOO/distfiles
  32. zfs create -o mountpoint=/var/cache/binpkgs $hostname/GENTOO/packages
  33. zfs create -o mountpoint=/var/db/repos $hostname/GENTOO/repos
  34. zfs create $hostname/GENTOO/repos/gentoo</code></pre>
  35. <h2 id="config">Configuring <a href="#config">§</a></h2>
  36. <p>USE flags:</p>
  37. <pre><code>sys-boot/grub libzfs device-mapper
  38. sys-fs/zfs rootfs
  39. sys-fs/zfs-kmod rootfs
  40. sys-kernel/genkernel cryptsetup</code></pre>
  41. <p>Now you need: <code>sys-boot/grub sys-fs/zfs sys-fs/zfs-kmod sys-kernel/genkernel</code>. You can also replace genkernel with dracut.</p>
  42. <p>Configuring ZFS for boot-up: <code>rc-update add zfs-import boot &amp;&amp; rc-update add zfs-mount &amp;&amp; rc-update add zfs-zed</code></p>
  43. <h3 id="initrd">initramfs (genkernel) <a href="#initrd">§</a></h3>
  44. <pre><code>mv /etc/genkernel.conf /etc/genkernel.conf.dist
  45. cat &gt;/etc/genkernel.conf &lt;&lt;-EOF
  46. GK_SHARE="${GK_SHARE:-/usr/share/genkernel}"
  47. CACHE_DIR="/var/cache/genkernel"
  48. DISTDIR="/var/cache/distfiles"
  49. LOGFILE="/var/log/genkernel.log"
  50. DEFAULT_KERNEL_SOURCE="/usr/src/linux"
  51. LOGLEVEL=1
  52. INSTALL="yes"
  53. SYMLINK="yes"
  54. BUSYBOX="yes"
  55. LUKS="yes"
  56. ZFS="yes"
  57. DISKLABEL="yes"
  58. KERNEL_SYMLINK_NAME="vmlinuz"
  59. COMPRESS_INITRD="yes"
  60. COMPRESS_INITRD_TYPE="best"
  61. INITRAMFS_SYMLINK_NAME="initramfs"
  62. MICROCODE_INITRAMFS="yes"
  63. EOF
  64. genkernel initramfs</code></pre>
  65. <h3 id="grub">GRUB <a href="#grub">§</a></h3>
  66. <p>As grub-mkconfig is a piece of crap which does unreadable config, I do it myself. Here it is:</p>
  67. <pre><code>#/boot/grub/grub.cfg
  68. insmod part_gpt
  69. insmod cryptodisk
  70. insmod luks
  71. insmod gcry_rijndael
  72. insmod gcry_sha512
  73. insmod zfs
  74. cryptomount -u 1c578f43-6f16-497c-ba88-986609ffa1d6
  75. set root=(crypto0)
  76. set prefix=(crypto0)/ROOT/default/@/boot/grub
  77. insmod gzio
  78. menuentry 'Gentoo' {
  79. linux /ROOT/default/@/boot/vmlinuz root=ZFS=rpool/ROOT/default crypt_root=UUID=1c578f43-6f16-497c-ba88-986609ffa1d6 dozfs=cache rootfstype=zfs
  80. initrd /ROOT/default/@/boot/initramfs
  81. }
  82. </code></pre>
  83. <p>And that should be all !</p>
  84. </article>