Encrypting your Linux system with LUKS and ZFS
Universal Kernel to Start
At the first attempt, a kernel with many features is recommended to ensure an operational system. (Having a generic kernel is also worthwhile to be able to boot with other hardware in case of defects.) If the first tests of your future production system are positive, you can remove unused drivers from the kernel.
The code shown in this article was created on a virtual machine. To make it as versatile as possible, lines 8 to 10 (Listing 4) use the kernel config
from the Live DVD.
Now it's time to configure the kernel (e.g., with make menuconfig
). Here it is important to enable SPL and ZFS (Figure 1).
Compiling and linking can take some time. Experienced Gentoo users can reduce the time by setting the MAKEOPTS
variable in /etc/genkernel.conf
to reflect the number of CPU cores:
MAKEOPTS="-j3" # for two cores
The genkernel all
command now triggers the compiler run. It is equally essential to build the initramfs:
genkernel --luks --zfs --disklabel initramfs
With its help, the kernel can open the LUKS device at boot time and subsequently access the ZFS pool and the filesystems it houses, such as /
, /usr
, /var
, and so on.
The following command installs the sys-fs/zfs
package:
emerge sys-fs/zfs
Because of the defined dependencies, the Gentoo Portage system knows that ZFS needs sys-kernel/spl
and automatically installs the dependency. The next lines ensure that the zfs
service is active in the relevant runlevels – the first one tells it to start at boot time, the second exports the pool at shutdown:
rc-update add zfs boot rc-update add zfs-shutdown shutdown
Do not forget to set the root password using passwd
.
Completing the System Setup
The rest of the installation follows the path of a classic Gentoo setup; in other words, it sets system parameters and installs basic services such as cron and syslog-ng.
The bootloader can be the modern GRUB version 2.00 or the legacy GRUB. For simplicity's sake, I will use GRUB 0.97 here:
emerge grub mount /dev/sda1 /boot grub-install /dev/sda
The configuration file, /boot/grub/grub.conf
in Listing 5, contains the kernel options that open the encrypted ZoL pool correctly.
Listing 5
grub.conf
To prepare the system for the first standalone boot, you need to edit the /etc/fstab
. Contrary to usual conventions, you'll be commenting out the lines for BOOT
, ROOT
, and SWAP
here, because the ZFS pool will handle these assignments. The following commands
exit cd zfs umount-a
exit the chroot environment and unmount the filesystems.
Mountpoint Preparation
The final step of this fairly extensive guide adapts the property of the pool mountpoint. In the installation environment, the pool was mounted at /mnt/gentoo
; on the production system, you will naturally want to use /
:
zfs set mountpoint=/ rpool
Finally, unmount the other filesystems and export the ZFS pool:
umount -l /mnt/gentoo/dev{/shm,/pts} umount -l /mnt/gentoo{/boot,/proc} zpool export rpool
A reboot of the PC or laptop without the Live DVD shows that everything was successful. If you followed all of these steps correctly, the booted Gentoo will prompt you for the passphrase for the LUKS device. And, if you provide this, the computer will then boot from the decrypted ZFS pool. You can now check out the new environment with zfs list
.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.