./build.sh [ command [ arguments ] ]
update # Update source code
clean # Clean up source code
build # Build kernel from source
install [ {KERNEL_TARGET_DIR} [ {KERNEL_SUFFIX} ] ]
#
# Install kernel to WSL2
#
# Optional arguments:
#
# - KERNEL_TARGET_DIR indicates the directory where the Kernel is stored on Windows
#
# Default: "C:\wsl2_zfs"
# Note: Can be given as a Windows path, or WSL path.
#
# - KERNEL_SUFFIX specifies a suffix to be added to the resulting kernel-name:
# e.g. "kernel-5.15.90.1_zfs-2.1.9-1_SUFFIX.bin".
#
# Default: no suffix.
# Note: This parameter requires KERNEL_TARGET_DIR to be set.
# However, you can use "" if you still want to use the default value.
debs # Install zfs command-line binaries to current distro
wslu # Install/upgrade WSL Utilities command-line binaries to current distro
env # Install building environment
help # Show this help
info # Show information about directories and source versions
version # Show the script's version
-
For a fresh install, get the code:
git clone https://github.com/multiheaded/zfs_on_wsl2.git && cd zfs_on_wsl2
If you already have the repo, just run
git pull
to get any updates.
-
Get/update the WSL2-modified Linux kernel and OpenZFS source code:
/bin/bash build.sh update
Note: Should already set the
WSL2-Linux-Kernel
andzfs
submodules under the3rdparty
directory to the correct tags. Verify and checkout fitting versions if necessary!
-
In case you had built the kernel before, first clean the source tree:
/bin/bash build.sh clean
WARNING: this will reset any changes you made under the
3rdparty/WSL2-Linux-Kernel
and3rdparty/zfs
directories!
-
Start the build:
/bin/bash build.sh
- Kernel will be
3rdparty/WSL2-Linux-Kernel/arch/x86/boot/bzImage
.deb
files are created as3rdparty/zfs/*.deb
-
Install the kernel and update
.wslconf
/bin/bash install
Note: For more installation options, see the syntax of the
install
command above or in the./build.sh help
command output.
-
Install the zfs command-line utilities
/bin/bash debs
Warning: The installation of these binaries might fail due to missing dependencies or unresolved conflicts.
Note: It is also possible to use the zfs binaries supplied by the package maintainers of your distribution.
-
Install your newly built kernel by copying it to Windows:
# Create a directory on "Windows" path to store the kernel mkdir -p /mnt/c/wsl2_zfs # Copy the Kernel file cp 3rdparty/WSL2-Linux-Kernel/arch/x86/boot/bzImage /mnt/c/wsl2_zfs/kernel
-
Also install the command-line utilities:
sudo dpkg -i 3rdparty/zfs/zfs_*_amd64.deb 3rdparty/zfs/lib*.deb
-
In your Windows 10 environment, create or edit
%userprofile%/.wslconfig
and have it point to your kernel file. Copy and rename if necessary.[wsl2] kernel=c:\\wsl2_zfs\\kernel localhostForwarding=true swap=0
-
Start a PowerShell with administrator privileges, stop your WSL instances and restart LxssManager
wsl --shutdown Restart-Service LxssManager
-
In your WSL2 environment, you should now be able to run
sudo zfs version
and get appropriate version information about ZFS.
To actually use it, check your drive paths from Powershell
wmic diskdrive list brief
and mount (bare) to WSL
wsl --mount \\.\PHYSICALDRIVE1 --bare
You can see that drive in Linux
lsblk
and zfs import {pool}
or create a new pool from scratch.