-
Notifications
You must be signed in to change notification settings - Fork 9
/
zfs-on-wsl.sh
97 lines (86 loc) · 3.12 KB
/
zfs-on-wsl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env sh
set -xeu
KERNELNAME="penguins-rule"
KERNELDIR="/opt/zfs-on-wsl-kernel"
ZFSDIR="/opt/zfs-on-wsl-zfs"
# Install deps
# Install pre-requisites
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update && \
sudo apt-get --autoremove upgrade -y && \
sudo apt-get install -y tzdata && \
sudo apt-get install -y \
alien \
autoconf \
automake \
bc \
binutils \
bison \
build-essential \
curl \
dkms \
fakeroot \
flex \
gawk \
libaio-dev \
libattr1-dev \
libblkid-dev \
libelf-dev \
libffi-dev \
libssl-dev \
libtirpc-dev \
libtool \
libudev-dev \
python3 \
python3-cffi \
python3-dev \
python3-setuptools \
uuid-dev \
wget \
zlib1g-dev
# Remove the Ubuntu-provided ZFS utilities if we have them
# (our build process will build them later)
sudo apt-get purge -y zfsutils-linux
# Create kernel directory
sudo mkdir -p $KERNELDIR $ZFSDIR
sudo chown -R user:user $KERNELDIR $ZFSDIR
# Clone Microsoft kernel source or update it and reset it if it already exists
test -d $KERNELDIR/.git || git clone --branch linux-msft-wsl-"$(uname -r | cut -d- -f 1)" --single-branch --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel.git $KERNELDIR
# Enter kernel source dir and update it
(cd $KERNELDIR && git reset --hard && git pull)
# Update existing kernel config with any custom config options we want
#
# Here, we enable CONFIG_USB_STORAGE to enable USB Mass Storage support,
# which does not appear to be enabled by default in Microsoft's kernel config
# but is needed for passing through USB devices to use for ZFS
export KCONFIG_CONFIG="Microsoft/config-wsl"
echo "CONFIG_USB_STORAGE=y" >> "$KERNELDIR/$KCONFIG_CONFIG"
# Prep kernel and use the defaults for any new config options we just unlocked
# by enabling USB_STORAGE
(cd $KERNELDIR && make olddefconfig && make prepare scripts)
# Clone ZFS, configure it and build/install the userspace binaries
#
# We could do this with the `native-deb` target added in OpenZFS 2.2, but that uses pre-configured
# paths for Debian and Ubuntu and the documentation does not recommend overriding it to use a kernel
# installed in a non-default location. TODO: I will see if I can sort this later.
#
# See: https://openzfs.github.io/openzfs-docs/Developer%20Resources/Building%20ZFS.html
test -d $ZFSDIR/.git || git clone --depth 1 https://github.com/zfsonlinux/zfs.git $ZFSDIR
(
cd $ZFSDIR || exit
git pull
sh autogen.sh
./configure --prefix=/ --libdir=/lib --includedir=/usr/include --datarootdir=/usr/share --enable-linux-builtin=yes --with-linux=$KERNELDIR --with-linux-obj=$KERNELDIR
./copy-builtin $KERNELDIR
make -j "$(nproc)"
sudo make install
)
# Enable statically compiling in ZFS, and build kernel
echo "CONFIG_ZFS=y" >> "$KERNELDIR/$KCONFIG_CONFIG"
(cd $KERNELDIR && make -j "$(nproc)" LOCALVERSION="-$KERNELNAME")
# Copy our kernel to C:\ZFSonWSL\bzImage
# (We don't save it as bzImage in case we overwrite the kernel we're actually running
# so after the build process is done, the user will need to shutdown WSL and then rename
# the bzImage-new kernel to bzImage)
mkdir -p /mnt/c/ZFSonWSL
cp -fv "${KERNELDIR}/arch/x86/boot/bzImage" "/mnt/c/ZFSonWSL/bzImage-new"