Skip to content

Instantly share code, notes, and snippets.

@dko1905
Last active October 19, 2022 17:44
Show Gist options
  • Save dko1905/e5f2a8bbca8bf74331fdb74a3f8f35a2 to your computer and use it in GitHub Desktop.
Save dko1905/e5f2a8bbca8bf74331fdb74a3f8f35a2 to your computer and use it in GitHub Desktop.
Void Linux on ZFS/LUKS

Void Linux on ZFS/LUKS

This guide may not work!

Requirements

  • EFI compatible computer
  • Void Linux live media with ZFS loaded, for example hrmpf

Partitions

Create three partitions:

Device Size Mount point Description
/dev/sda1 600M /boot/efi EFI partition
/dev/sda2 1G /boot Unencrypted boot partition
/dev/sda3 %FREE / Encrypted ZFS/LUKS partition

Format filesystems:

mkfs -t vfat /dev/sda1
mkfs -t ext4 /dev/sda2

LUKS & ZFS

# Encrypt /dev/sda3
cryptsetup luksFormat \
  --cipher aes-xts-plain64 \
  --key-size 256 \
  --hash sha256 \
  --iter-time 5000 \
  --use-random \
  --type luks2 \
  /dev/sda3
# Map /dev/sda3
cryptsetup open \
  --type luks2 \
  /dev/sda3 crypt
# Create pool
zpool create \
  -O atime=off \
  -m none \
  -R /mnt \
  -O compression=lz4 \
  tank /dev/mapper/crypt
# 'zpool status' should now show a new pool with the name 'tank'.
# Let's create required datasets:
zfs create -o mountpoint=none -o canmount=off tank/ROOT
zfs create -o mountpoint=/ tank/ROOT/default
# And now the optional datasets:
zfs create -o mountpoint=/home tank/home
zfs create -o mountpoint=/var tank/var
zfs create -o mountpoint=/log tank/log

Mount partitions

# Mount /boot
mkdir -p /mnt/boot
mount -t ext4 /dev/sda2 /mnt/boot
# Mount /boot/efi
mkdir -p /mnt/boot/efi
mount -t vfat /dev/sda1 /mnt/boot/efi
# Mount "special" devices
for dir in dev proc sys run; do mkdir -p /mnt/$dir ; mount --rbind /$dir /mnt/$dir ; mount --make-rslave /mnt/$dir ; done

Configure chroot

# Install required packages (might take a while)
xbps-install -Sy -R https://alpha.de.repo.voidlinux.org/current -r /mnt base-system cryptsetup grub-x86_64-efi zfs vim
# Enter chroot and configure Void Linux
chroot /mnt
chown root:root /
chmod 755 /
passwd root
echo voidvm > /etc/hostname
echo "LANG=en_US.UTF-8" > /etc/locale.conf
echo "en_US.UTF-8 UTF-8" >> /etc/default/libc-locales
xbps-reconfigure -f glibc-locales
chsh -s /bin/bash
# create a new file in /etc/dracut.conf.d/override.conf
# containing the following line
hostonly=yes
omit_dracutmodules+="btrfs"

set timezone: list timezones by ls -F /usr/share/zoneinfo/

rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hwclock --systohc # generate /etc/adjtime and set HW RTC to UTC

Fstab & crypttab

While in the chroot, you need to edit /etc/fstab and /etc/crypttab:

# /etc/fstab
# add theese lines:
/dev/sda2       /boot   ext4    defaults                0       0
/dev/sda1       /boot/efi vfat  defaults                0       0
# /etc/crypttab
# add theese lines:
crypt    /dev/sda3    none    luks

Grub

Get the UUID of /dev/sda3 and replace XXX with it.

# /etc/default/grub
# change GRUB_CMDLINE_LINUX_DEFAULT to this
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=4 rd.luks.allow-discards rd.luks.name=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=crypt rootfstype=zfs"

Now install grub:

mount -t efivarfs none /sys/firmware/efi/efivars # ONLY add if next line fails
grub-install \
    --target=x86_64-efi \
    --efi-directory=/boot/efi \
    --boot-directory=/boot

Generate grub config:

export ZPOOL_VDEV_NAME_PATH=YES
grub-mkconfig -o /boot/grub/grub.cfg

Last step is to regenerate the initramfs:

# Might be other kernel version
xbps-reconfigure -f linux5.15

All done, we are now ready to reboot into void linux:

# exit the chroot
exit
# unmount recursively from /mnt
umount -R /mnt
reboot

Based upon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment