Last active
March 29, 2021 22:37
-
-
Save useafterfree/a265eb04aef8c8f3620cca51babfbe56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LINUX_VERSION=5.9-rc7 | |
LINUX_KERNEL_VERSION=mainline-${LINUX_VERSION} | |
ZFS_VERSION=0.8.6 | |
# Find ROOT_DIR | |
ROOT_DIR=/c | |
if [ ! -z "$(ls -A /mnt/c)" ]; then | |
ROOT_DIR=/mnt/c | |
fi | |
if [ -z "$(ls -A ${ROOT_DIR})" ]; then | |
echo "ROOT_DIR ${ROOT_DIR} is empty, exiting." | |
exit; | |
fi | |
echo "Found ${ROOT_DIR}" | |
NEW_KERNEL_VERSION=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) | |
echo "Building ... kernel-fs-gpu-zfs.${NEW_KERNEL_VERSION}" | |
BUILD_DIR=${HOME}/build | |
mkdir -p ${BUILD_DIR} | |
cd ${BUILD_DIR} | |
if [[ ! -f config-wsl ]]; then | |
curl -O https://raw.githubusercontent.com/microsoft/WSL2-Linux-Kernel/master/Microsoft/config-wsl | |
fi | |
if [[ ! -d linux-${LINUX_KERNEL_VERSION} ]]; then | |
curl -L https://github.com/linux-wsl2/linux-mainline/archive/v${LINUX_VERSION}.tar.gz | tar -xz | |
fi | |
if [[ ! -d zfs ]]; then | |
git clone https://github.com/openzfs/zfs | |
cd zfs | |
git checkout master | |
cd -- | |
fi | |
# Install the build tools and the dependencies | |
sudo apt update | |
sudo apt install -yqq build-essential autoconf automake libtool gawk alien fakeroot dkms libblkid-dev uuid-dev libudev-dev libssl-dev \ | |
zlib1g-dev libaio-dev libattr1-dev libelf-dev python3 python3-dev python3-setuptools python3-cffi libffi-dev flex bison libncurses5-dev | |
export CONFIG=${BUILD_DIR}/linux-${LINUX_KERNEL_VERSION}/.config | |
cp config-wsl ${CONFIG} | |
cat <<EOT >> ${CONFIG} | |
CONFIG_X86_INTEL_TSX_MODE_OFF=y | |
CONFIG_LEGACY_VSYSCALL_NONE=y | |
CONFIG_VIRTIO_FS=y | |
CONFIG_DM_INIT=y | |
CONFIG_VIRTIO_BLK_SCSI=y | |
CONFIG_NF_CONNTRACK_BRIDGE=y | |
CONFIG_LOCALVERSION="-microsoft-zfs-gpu.${NEW_KERNEL_VERSION}" | |
CONFIG_UNICODE=y | |
CONFIG_NET_9P_VIRTIO=y | |
CONFIG_ZFS=y | |
CONFIG_DXGKRNL=y | |
EOT | |
cd linux-${LINUX_KERNEL_VERSION} | |
# make prepare scripts | |
# make menuconfig | |
make olddefconfig | |
# make -j | |
# make scripts | |
## ZFS | |
cd ${BUILD_DIR}/zfs | |
git checkout master | |
git pull | |
sh autogen.sh | |
./configure --prefix=/ --libdir=/lib --includedir=/usr/include --datarootdir=/usr/share --enable-linux-builtin=yes \ | |
--with-linux=$BUILD_DIR/linux-${LINUX_KERNEL_VERSION} \ | |
--with-linux-obj=$BUILD_DIR/linux-${LINUX_KERNEL_VERSION} | |
./copy-builtin $BUILD_DIR/linux-${LINUX_KERNEL_VERSION} | |
time make -j | |
sudo make install | |
# Enter the kernel directory | |
cd ${BUILD_DIR}/linux-${LINUX_KERNEL_VERSION}/ | |
# Check if a ZFS reference already exist in the config file | |
if ! grep -s ZFS .config; then | |
# Add the ZFS reference to the end of the config file | |
echo "CONFIG_ZFS=y" >> .config | |
fi | |
## MAKE IT | |
make -j | |
# Install the modules built with the Kernel | |
sudo make modules_install | |
# Create a directory on "Windows" path to store the kernel | |
KERNEL_DIR=${ROOT_DIR}/wslkernel5 | |
mkdir -p ${KERNEL_DIR} | |
# Copy the Kernel file | |
echo "Copying arch/x86/boot/bzImage -> ${KERNEL_DIR}/kernel-fs-gpu-zfs.${NEW_KERNEL_VERSION}" | |
cp arch/x86/boot/bzImage ${KERNEL_DIR}/kernel-fs-gpu-zfs.${NEW_KERNEL_VERSION} | |
## Who is the default user on Windows? | |
LOGGED_IN_USER=$(powershell.exe \$env:UserName | sed $'s/[^[:print:]\t]//g') | |
echo "Found WSL2 running under: ${LOGGED_IN_USER}" | |
# Edit the wslconfig file and add the Kernel setting | |
USER_DIR=${ROOT_DIR}/Users/${LOGGED_IN_USER} | |
WSL_CONFIG=${USER_DIR}/.wslconfig | |
echo "Using ${WSL_CONFIG}" | |
sed -i "s/kernel-fs-gpu-zfs.\([0-9a-zA-Z]\+\)$/kernel-fs-gpu-zfs.${NEW_KERNEL_VERSION}/g" ${WSL_CONFIG} | |
if grep -s ${NEW_KERNEL_VERSION} ${WSL_CONFIG}; then | |
echo "DONE! Run: 'wsl.exe --shutdown' in a seperate command window."; | |
else | |
echo "Something went wrong." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment