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 (3698B)


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