Score:0

How to mount a zfs poolfile with dataset as a loopback?

bs flag

I have a installed Ubuntu 22.04.1 (from 22.04.1-desktop-amd64.iso), running at VirtualBox 7, with installed zfs-tools.

I have an image file from a zfs pool called zfsfile01. I can look in this file with:

fdisk -l zfsfile01

and I get the value with 2 datasets: dataset01 and dataset02 - the file seems to be ok.

Now I have to mount the file zfsfile01 itself or the second dataset02 as a loopback device. After reading some useful texts, I recognized that I have to first import the poolfile with zpool and then mount a filesystem (a dataset?) from the poolfile with zfs mount. Importing the pool with

zpool import <pathto>/zfsfile01

failed with:

cannot import <pathto>/zfsfile01: no such pool available

I guess because of the file and no right zfs pool.

Basically, I can go on with the mount command in Linux and can mount a dumped file with sudo mount -o loop,offset=xxx image.dd /tmp/destination and such stuff. But I don't know which options I have to use to mount a zfs pool file with dataset as a loop back device.

Here is the output of sudo fdisk -l zfsfile01: (response to comment)

Festplatte ewf1: 1,82 TiB, 2000398934016 Bytes, 3907029168 Sektoren
Einheiten: Sektoren von 1 * 512 = 512 Bytes
Sektorgröße (logisch/physikalisch): 512 Bytes / 512 Bytes
E/A-Größe (minimal/optimal): 512 Bytes / 512 Bytes
Festplattenbezeichnungstyp: gpt
Festplattenbezeichner: 44E0E83D-A9CA-11EC-xxxx-xxxxx
Gerät       Anfang       Ende       Sektoren   Größe Typ
dataset1    128          4194431    4194304    2G FreeBSD Swap
dataset2    4194432      3907029127 3902834696 1,8T FreeBSD ZFS

Here is the output of losetup: (response to Artur's answer)

$ losetup -f
/dev/loop8
$ sudo losetup /dev/loop8 /media/sf_E_DRIVE/zfsfile01
losetup: /media/sf_E_DRIVE/zfsfile01: Loop-Gerät konnte nicht eingerichtet werden: Vorgang nicht zulässig

I can loop a dd image with:

sudo losetup /dev/loop8 /media/image.dd 

and then I can un-loop the device with:

sudo losetup -d /dev/loop8

But I get an error with zfsfile01:

Loop-Gerät konnte nicht eingerichtet werden: Vorgang nicht zulässig

which means:

cannot setup loop-device: progress is not valid
Artur Meinild avatar
vn flag
I don't know what "imagefile from a zfs pool" means - but what is the name of the zpool? You should be able to do `zpool import <zpool-name>`.
Alois avatar
bs flag
@guiverc: Its a ubuntu 22.04.1-desktop-amd64.iso on virtualbox 7.0
Alois avatar
bs flag
@artur meinild: i got a file with the size of 2 TB. the owner said to me: this is the image of a NAS-partition (how ever...) and this is a zfs pool with datasets in it. It seems to be ok so far, the fdisk -l zfsfile01 said, that the type is zfs and there are two datasets in it.
Alois avatar
bs flag
@artur meinild: no, sorry the zpool import <pathto>/zfsfile01 dont work. i got a error: "cannot import /zfsfile01: no such pool available"
Artur Meinild avatar
vn flag
Could you list the complete output of `fdisk -l zfsfile01` in your question? Thanks.
Artur Meinild avatar
vn flag
It doesn't look like the image contains ZFS datasets, but rather that the "datasets" are actually partitions - where only partition 2 contains a Zpool. So you should probably find a way to only mount partition 2 from the file as a loopback, and then import the zpool from this partition.
Artur Meinild avatar
vn flag
Also please note that these are FreeBSD partitions, and not Linux partitions. This might be why it's not working out of the box.
Alois avatar
bs flag
Artur, i will ask with these insights a new question. Thanks a lot to you!
Alois avatar
bs flag
I went to forums.freebsd.org, if i have new insights, i will post these here. Alois.
Score:1
vn flag

I found a guide here, that hopefully is applicable to your case.

This is how I would translate it to your situation:

  1. Mount image as loop device:

    # losetup /dev/loop100 /<pathto>/zfsfile01
    
  2. Create partitions (only if the image contains partitions):

    # kpartx -av /dev/loop100
    add map loop100p1 (252:0): <something>
    add map loop100p9 (252:1): <something>
    
  3. Create mount point:

    # mkdir /mnt/<poolname>
    
  4. Try to import the ZFS pool with this pool name:

    # zpool import -R /mnt/<poolname> -d /dev/mapper
       pool: <poolname>
         id: <specific ID>
      state: ONLINE
     status: Some supported features are not enabled on the pool.
     action: The pool can be imported using its name or numeric identifier, though
             some features will not be available without an explicit 'zpool upgrade'.
     config:
    
            <poolname>       ONLINE
              loop100        ONLINE
    
  5. With the ID from previous result, you can import the pool with new options and name (if necessary - maybe you can skip this step and just use <poolname> in the following):

    # zpool import -o readonly=on -f -d /dev/mapper <specific ID> <new_poolname> -R /mnt/<poolname>
    
  6. Done:

    # zpool status
      pool: <new_poolname>
     state: ONLINE
    status: Some supported features are not enabled on the pool. The pool can
            still be used, but some features are unavailable.
    action: Enable all features using 'zpool upgrade'. Once this is done,
            the pool may no longer be accessible by software that does not support
            the features. See zpool-features(5) for details.
      scan: none requested
    config:
    
            NAME             STATE     READ WRITE CKSUM
            <new_poolname>   ONLINE       0     0     0
              loop100        ONLINE       0     0     0
    
    errors: No known data errors
    
    # zfs list <new_poolname> -r
    NAME                       USED  AVAIL  REFER  MOUNTPOINT
    <new_poolname>             xxxM  xxxxG  xxK  /mnt/<poolname>
    <new_poolname>/dataset01   xxxM  xxxxG  xxK  /mnt/<poolname>/dataset01
    <new_poolname>/dataset02   xxxM  xxxxG  xxK  /mnt/<poolname>/dataset02
    
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.