zfs-on-wsl icon indicating copy to clipboard operation
zfs-on-wsl copied to clipboard

Works for me, but I'm not able to make a file-based pool

Open rnickle opened this issue 3 years ago • 5 comments

Thanks, this works great. I did the same flow based on https://wsl.dev/wsl2-kernel-zfs/ and wrote a script somewhat like yours. I was trying to use this to create a unit testing environment for ZFS scripts, so my goal is to create a pool using temp files, run the tests and then discard the pool. I'm applying it to Ubuntu 20.04 (from the Microsoft Store.)

I used Linux 5.10.60 for my build, but as you did, ZFS 2.10, but zpool doesn't work:

root:/usr/src# for i in {1..4}; do dd if=/dev/zero of=/root/vdev$i.img bs=1024 count=98304; done
root:/usr/src# zpool create testpool /root/vdev?.img
cannot create 'testpool': no such pool or dataset

Here's the same file-based temp file pool on a non-WSL VM with Ubuntu 20.04 built with the Ubuntu installer:

# for i in {1..4}; do dd if=/dev/zero of=/tmp/dev$i.img bs=1024 count=98304; done
# zpool create testpool /tmp/vdev?.img
# zpool list
NAME       SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
bpool     1.88G  78.8M  1.80G        -         -     0%     4%  1.00x    ONLINE  -
rpool       26G  2.07G  23.9G        -         -     1%     7%  1.00x    ONLINE  -
testpool   192M   112K   192M        -         -     0%     0%  1.00x    ONLINE  -

So I tried your excellent implementation, and it worked flawlessly, but I still end up in the same state.

Thanks for considering, I'm still digging, I will add more data if I find anything interesting.

rnickle avatar Aug 21 '21 01:08 rnickle

Thanks for letting me know, @rnickle! I'm glad someone actually found this and was able to get some use out of it.

I have been having a similar issue myself actually when trying to test pool configurations using sparse files. I need to rework my Win 10 development environment to really give this a proper test. Got a bit stuck as they've removed all the Insider Preview builds of Win 10 to get ready for the Win 11 release, but my dev box is too old to upgrade to 11. So for now I'm stuck unable to get the latest WSL2 with the nice drive mapping features.

It shouldn't really be needed for testing pools with sparse files, but I wanted to make sure I could get it reliably working with passed-through disks before I started to debug the sparse file issue too hard - in case both showed the same behaviour.

I'll rework my dev env and see if I can work out what we might be missing here.

alexhaydock avatar Aug 21 '21 10:08 alexhaydock

Thanks for looking into it, so your suggestion about the drive mapping is what I was planning to try next: try to mount a VHD, I can try that later today.

I tried strace and gdb but wasn't able to get any clues that way, perhaps I'm not trying hard enough yet. I pored over the source but no ideas.

For my development environment I'm working in a vanilla but up-to-date corporate Win 10 Pro environment, I could use my personal Win 10 environment for testing too, but neither of these machines are on insider builds (that's a good idea!) For a point of reference I have a very clean Ubuntu 20.04 VM which is successfully running ZFS.

I wonder if it is because it is a kernel built-in, but that doesn't make sense. It is almost as if there is some service element missing, and yet, the services in the systemd directory seem mostly related to mounting services, not pool services.

One thing I noticed with sysctl is that the kernel.spl.hostid was set to '0', which didn't seem right since that was set to the host ID on my Ubuntu reference. Running 'zgenhostid' was sufficient to get the WSL session to generate an /etc/hostid file and set the kernel variable: kernel.spl.hostid = 2bd45778

But that didn't change the behavior of creating a zpool. Still wondering if there's some other metadata or prerequisite that needs to be set to enable the zfs commands to access those features in the kernel.

Thanks!

rnickle avatar Aug 21 '21 15:08 rnickle

I posed a Q&A on the OpenZFS project: Statically linked module for WSL2, does not seem to initialize properly. #12503

Great idea! I haven't had the time to do much debugging here directly myself, but I've upvoted your discussion thread and I subscribed to it so I can see how things progress over there.

alexhaydock avatar Aug 23 '21 15:08 alexhaydock

I thought I might have some great insight by refactoring the flow to build a kernel with loadable modules instead of static linking, but I have exactly the same results:

# lsmod
Module                  Size  Used by
# modprobe zfs
# lsmod
Module                  Size  Used by
zfs                  4300800  0
zunicode              335872  1 zfs
zzstd                 569344  1 zfs
zlua                  172032  1 zfs
zavl                   16384  1 zfs
icp                   311296  1 zfs
zcommon                86016  2 zfs,icp
znvpair                69632  2 zfs,zcommon
spl                    90112  6 zfs,icp,zzstd,znvpair,zcommon,zavl
# zpool create testpool /root/vdev1.img 
cannot create 'testpool': no such pool or dataset

rnickle avatar Aug 30 '21 14:08 rnickle