4

So I have to mount an encrypted zfs partition to fix my computer. I have looked everywhere but I can't mount it with the info I found. Every time I do sudo zfs set mountpoint=/mnt/k/ rpool it does not fail but I can't get to the files. If I mount it in disks I get error mounting /dev/sda4 to /media/ubuntu/rpool2: unknown filesystem type zfs_member (udisk-error-quark, 0). Most likely the partition is not mounting because it is encrypted. How do I mount it?

Andra
  • 172
jon_will
  • 43
  • 4

1 Answers1

2

You can use the below example workflow to perform the following:

  1. Install ZFS and verify the installation
  2. Locate and import a ZFS pool from a disk partition
  3. Set the mountpoint of the desired ZFS pool and/or dataset
  4. Decrypt they ZFS pool keystore
  5. Mount the cipher key and load it into ZFS
  6. Mount your ZFS pool and/or dataset to the desired point
ZFS_DISK='/dev/sdX'
ZFS_POOL_PARTITION='/dev/sdXn'
ZFS_POOL='rpool'
ZFS_POOL_DATASET='DATA'  # 'ROOT' or 'USERDATA' for Ubuntu
MOUNTPOINT='/mnt'

install zfs (using apt-get, yum, dnf, pacman, etc)

sudo apt-get install zfsutils-linux sudo zfs --version

locate zfs disk and pool

sudo lsblk -af "$ZFS_DISK" sudo fdisk -l "$ZFS_DISK"

create mountpoint directories for zfs pool and cipher key

sudo mkdir -p "$MOUNTPOINT" sudo mkdir -p /zfskey

import pool from partition

sudo zpool import -d "$ZFS_POOL_PARTITION" "$ZFS_POOL" sudo zpool list sudo zpool status -P "$ZFS_POOL"

get and set the mountpoint for our zfs pool/dataset

NOTE: mountpoints may collide with current filesystem,

as mountpoints inherit from higher-level mountpoints

sudo zfs get mounted "$ZFS_POOL" -t filesystem -r sudo zfs get mountpoint "$ZFS_POOL" -t filesystem -r sudo zfs get mountpoint "$ZFS_POOL/$ZFS_POOL_DATASET" # BACKUP THIS VALUE sudo zfs set mountpoint="$MOUNTPOINT" "$ZFS_POOL/$ZFS_POOL_DATASET"

decrypt zfs keystore and load cipher key

sudo cryptsetup open "/dev/zvol/$ZFS_POOL/keystore" zfskey # creates /dev/dm-0 dm-1 dm-2 ls -l /dev/mapper/zfskey # /dev/mapper/zfskey -> /dev/dm-n sudo cryptsetup -v status zfskey sudo mount /dev/mapper/zfskey /zfskey df -H ls -l /zfskey sudo cat /zfskey/system.key | sudo zfs load-key -L prompt "$ZFS_POOL"

mount the decrypted pool and/or dataset

sudo zfs mount "$ZFS_POOL/$ZFS_POOL_DATASET" sudo zfs list ls -la "$MOUNTPOINT"

Your directory should now be mounted and visible.

  • Most comprehensive answer I found on mounting a ZFS filesystem, saved my day. Needs to get higher ratings so people can see this before going to the others. – Bim Feb 24 '24 at 19:13